| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | # Dependencies |
|---|
| 4 | require_once(PLUGINS . 'autoreader/helper/edit.helper.php' ); |
|---|
| 5 | require_once(PLUGINS . 'autoreader/autoreader.php'); |
|---|
| 6 | $arSettings = new Autoreader($h); |
|---|
| 7 | |
|---|
| 8 | $id = 0; |
|---|
| 9 | $action = $h->cage->post->testAlnumLines('action'); |
|---|
| 10 | $action_get = $h->cage->get->testAlnumLines('action'); |
|---|
| 11 | if (!$action) { $action = $action_get; } |
|---|
| 12 | switch ($action) { |
|---|
| 13 | case "edit": |
|---|
| 14 | $data = $arSettings->adminEdit($h); |
|---|
| 15 | //print_r($data); |
|---|
| 16 | echo '<h2>Editing Campaign #' . $data['main']['id'] . ", " . $data['main']['title'] . '</h2>'; |
|---|
| 17 | action_add($h, $arSettings, $data, 'edit'); |
|---|
| 18 | // what $data settings are needed |
|---|
| 19 | break; |
|---|
| 20 | case "save" : |
|---|
| 21 | $arSettings->adminCampaignRequest($h); |
|---|
| 22 | if ( $h->cage->post->keyExists('campaign_edit') ) { |
|---|
| 23 | $cid = $h->cage->post->getInt('campaign_edit'); |
|---|
| 24 | $arSettings->adminProcessEdit($h,$cid); |
|---|
| 25 | } |
|---|
| 26 | else { |
|---|
| 27 | $arSettings->adminProcessAdd($h); |
|---|
| 28 | }; |
|---|
| 29 | exit; // this is an ajax return call, so we don't want any html echoing to the screen |
|---|
| 30 | case "test_feed" : |
|---|
| 31 | $data = $h->cage->post->testUri('url'); |
|---|
| 32 | $arSettings->adminTestfeed($data); |
|---|
| 33 | exit; // this is an ajax return call, so we don't want any html echoing to the screen |
|---|
| 34 | default : |
|---|
| 35 | echo '<h2>Add New Campaign</h2>'; |
|---|
| 36 | action_add($h, $arSettings); |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | ?> |
|---|
| 40 | |
|---|
| 41 | <div class="wrap"> |
|---|
| 42 | |
|---|
| 43 | <?php |
|---|
| 44 | function action_add($h, $arSettings, $data=null, $action = 'add') { |
|---|
| 45 | |
|---|
| 46 | ?> |
|---|
| 47 | <form id="edit_campaign" action="" method="post" accept-charset="utf-8"> |
|---|
| 48 | |
|---|
| 49 | <?php |
|---|
| 50 | |
|---|
| 51 | if ($action=='edit') { |
|---|
| 52 | $id = $data['main']['id']; |
|---|
| 53 | echo input_hidden_tag('campaign_edit', $id); |
|---|
| 54 | } |
|---|
| 55 | else { |
|---|
| 56 | echo input_hidden_tag('campaign_add', 1); |
|---|
| 57 | $data = $arSettings->campaign_structure; |
|---|
| 58 | } |
|---|
| 59 | ?> |
|---|
| 60 | |
|---|
| 61 | <ul id="edit_buttons" class="submit"> |
|---|
| 62 | <li><a href="http://bloglinkjapan.com/wp-content/plugins/wp-o-matic/help.php?item=campaigns" class="help_link">Help</a></li> |
|---|
| 63 | <li><input type="submit" name="edit_submit" value="Submit" id="edit_submit" /></li> |
|---|
| 64 | </ul> |
|---|
| 65 | |
|---|
| 66 | <div id="admin_plugin_tabs"> |
|---|
| 67 | <ul class="tabs"> |
|---|
| 68 | <li class="current"><a href="#section_basic" id="tab_basic">Basic</a></li> |
|---|
| 69 | <li><a href="#section_feeds" id="tab_feeds">Feeds</a></li> |
|---|
| 70 | <li><a href="#section_categories" id="tab_categories">Categories</a></li> |
|---|
| 71 | <li><a href="#section_rewrite" id="tab_rewrite">Rewrite</a></li> |
|---|
| 72 | <li><a href="#section_options" id="tab_options">Options</a></li> |
|---|
| 73 | <?php if($action == 'edit'): ?> |
|---|
| 74 | <li><a href="#section_tools" id="tab_tools">Tools</a></li> |
|---|
| 75 | <?php endif ?> |
|---|
| 76 | </ul> |
|---|
| 77 | </div> |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | <div id="edit_sections"> |
|---|
| 81 | <!-- Basic section --> |
|---|
| 82 | <div class="section current" id="section_basic"> |
|---|
| 83 | <div class="longtext required"> |
|---|
| 84 | <?php echo label_for('campaign_title', 'Title') ?> |
|---|
| 85 | <?php echo input_tag('campaign_title', _data_value($data['main'], 'title')) ?> |
|---|
| 86 | <p class="note">Tip: pick a name that is general for all the campaign's feeds (eg: Paris Hilton)</p> |
|---|
| 87 | </div> |
|---|
| 88 | |
|---|
| 89 | <div class="checkbox required"> |
|---|
| 90 | <?php echo label_for('campaign_active', 'Active?') ?> |
|---|
| 91 | <?php echo checkbox_tag('campaign_active', 1, _data_value($data['main'], 'active', true)) ?> |
|---|
| 92 | <p class="note">If inactive, the parser will ignore these feeds</p> |
|---|
| 93 | </div> |
|---|
| 94 | |
|---|
| 95 | <div class="text"> |
|---|
| 96 | <?php echo label_for('campaign_slug', 'Campaign slug') ?> |
|---|
| 97 | <?php echo input_tag('campaign_slug', _data_value($data['main'], 'slug')) ?> |
|---|
| 98 | <p class="note">Optionally, you can set an identifier for this campaign. Useful for detailed track of your ad-revenue.</p> |
|---|
| 99 | </div> |
|---|
| 100 | </div> |
|---|
| 101 | |
|---|
| 102 | <!-- Feeds section --> |
|---|
| 103 | <div class="section" id="section_feeds"> |
|---|
| 104 | <p>Please fill in at least one feed. If you\'re not sure about the exact feed url, just type in the domain name, and the feed will be autodetected</p> |
|---|
| 105 | |
|---|
| 106 | <div id="edit_feed"> |
|---|
| 107 | <?php if(isset($data['feeds']['edit'])): ?> |
|---|
| 108 | <?php foreach($data['feeds']['edit'] as $id => $feed): ?> |
|---|
| 109 | <div class="inlinetext required"> |
|---|
| 110 | <?php echo label_for('campaign_feed_edit_' . $id, 'Feed URL') ?> |
|---|
| 111 | <?php echo input_tag('campaign_feed[edit]['. $id .']', $feed, 'disabled=disabled class=input_text id=campaign_feed_edit_' . $id) ?> |
|---|
| 112 | <?php echo checkbox_tag('campaign_feed[delete]['.$id.']', 1, (isset($data['feeds']['delete']) && _data_value($data['feeds']['delete'], $id)), 'id=campaign_feed_delete_' . $id) ?> <label for="campaign_feed_delete_<?php echo $id ?>" class="delete_label">Delete ?</label> |
|---|
| 113 | </div> |
|---|
| 114 | <?php endforeach ?> |
|---|
| 115 | <?php endif ?> |
|---|
| 116 | |
|---|
| 117 | <?php if(isset($data['feeds']['new'])): ?> |
|---|
| 118 | <?php foreach($data['feeds']['new'] as $i => $feed): ?> |
|---|
| 119 | <div class="inlinetext required"> |
|---|
| 120 | <?php echo label_for('campaign_feed_new_' . $i, 'Feed URL') ?> |
|---|
| 121 | <?php echo input_tag('campaign_feed[new]['.$i.']', $feed, 'class=input_text id=campaign_feed_new_' . $i) ?> |
|---|
| 122 | </div> |
|---|
| 123 | <?php endforeach ?> |
|---|
| 124 | <?php else: ?> |
|---|
| 125 | <?php for($i = 0; $i < 4; $i++): ?> |
|---|
| 126 | <div class="inlinetext required"> |
|---|
| 127 | <?php echo label_for('campaign_feed_new_' . $i, 'Feed URL') ?> |
|---|
| 128 | <?php echo input_tag('campaign_feed[new][]', null, 'class=input_text id=campaign_feed_new_' . $i) ?> |
|---|
| 129 | </div> |
|---|
| 130 | <?php endfor ?> |
|---|
| 131 | <?php endif ?> |
|---|
| 132 | </div> |
|---|
| 133 | |
|---|
| 134 | <a href="#add_feed" id="add_feed">Add more</a> | <a href="#" id="test_feeds">Check all</a> |
|---|
| 135 | </div> |
|---|
| 136 | |
|---|
| 137 | <!-- Categories section --> |
|---|
| 138 | <div class="section" id="section_categories"> |
|---|
| 139 | <p>These are the categories where the posts will be created once they're fetched from the feeds.</p> |
|---|
| 140 | <p>Please select at one.</p> |
|---|
| 141 | |
|---|
| 142 | <ul id="categories"> |
|---|
| 143 | <?php $arSettings->adminEditCategories($h, $data) ?> |
|---|
| 144 | </ul> |
|---|
| 145 | |
|---|
| 146 | <a href="#quick_add" id="quick_add">Quick add</a> |
|---|
| 147 | </div> |
|---|
| 148 | |
|---|
| 149 | <!-- Rewrite section --> |
|---|
| 150 | <div class="section" id="section_rewrite"> |
|---|
| 151 | <p>Want to transform a word into another? Or link a specific word to some website? |
|---|
| 152 | <?php // echo '<a href=' . $arSettings->helpurl . '" class="help_link">Read more</a>' ?></p> |
|---|
| 153 | |
|---|
| 154 | <ul id="edit_words"> |
|---|
| 155 | <?php if(isset($data['rewrites']) && count($data['rewrites'])): ?> |
|---|
| 156 | <?php foreach($data['rewrites'] as $i => $rewrite): ?> |
|---|
| 157 | <li class="word"> |
|---|
| 158 | <div class="origin textarea"> |
|---|
| 159 | <?php echo label_for('campaign_word_origin_' . $i, 'Origin') ?> |
|---|
| 160 | <?php echo textarea_tag('campaign_word_origin['.$i . ']', $rewrite['origin']['search'], 'id=campaign_word_origin_' . $rewrite->id) ?> |
|---|
| 161 | <label class="regex"> |
|---|
| 162 | <?php echo checkbox_tag('campaign_word_option_regex['. $i .']', 1, $rewrite['origin']['regex']) ?> |
|---|
| 163 | <span><?php _e('RegEx', 'wpomatic') ?></span> |
|---|
| 164 | </label> |
|---|
| 165 | </div> |
|---|
| 166 | |
|---|
| 167 | <div class="rewrite textarea"> |
|---|
| 168 | <label> |
|---|
| 169 | <?php echo checkbox_tag('campaign_word_option_rewrite['. $i .']', 1, isset($rewrite['rewrite'])) ?> |
|---|
| 170 | <span>Rewrite to:</span> |
|---|
| 171 | </label> |
|---|
| 172 | <?php echo textarea_tag('campaign_word_rewrite['. $i .']', _data_value($rewrite, 'rewrite')) ?> |
|---|
| 173 | </div> |
|---|
| 174 | |
|---|
| 175 | <div class="relink textarea"> |
|---|
| 176 | <label> |
|---|
| 177 | <?php echo checkbox_tag('campaign_word_option_relink['. $i .']', 1, isset($rewrite['relink'])) ?> |
|---|
| 178 | <span>Relink to:</span> |
|---|
| 179 | </label> |
|---|
| 180 | <?php echo textarea_tag('campaign_word_relink['. $i .']', _data_value($rewrite, 'relink')) ?> |
|---|
| 181 | </div> |
|---|
| 182 | </li> |
|---|
| 183 | <?php endforeach ?> |
|---|
| 184 | <?php else: ?> |
|---|
| 185 | <li class="word"> |
|---|
| 186 | <div class="origin textarea"> |
|---|
| 187 | <label for="campaign_word_origin_new1">Origin</label> |
|---|
| 188 | <textarea name="campaign_word_origin[new1]" id="campaign_word_origin_new1"></textarea> |
|---|
| 189 | <label class="regex"><input type="checkbox" name="campaign_word_option_regex[new1]" /> <span>RegEx</span></label> |
|---|
| 190 | </div> |
|---|
| 191 | <div class="rewrite textarea"> |
|---|
| 192 | <label><input type="checkbox" value="1" name="campaign_word_option_rewrite[new1]" /> <span>Rewrite to:</span></label> |
|---|
| 193 | <textarea name="campaign_word_rewrite[new1]"></textarea> |
|---|
| 194 | </div> |
|---|
| 195 | <div class="relink textarea"> |
|---|
| 196 | <label><input type="checkbox" value="1" name="campaign_word_option_relink[new1]" /> <span>Relink to:</span></label> |
|---|
| 197 | <textarea name="campaign_word_relink[new1]"></textarea> |
|---|
| 198 | </div> |
|---|
| 199 | </li> |
|---|
| 200 | <?php endif ?> |
|---|
| 201 | </ul> |
|---|
| 202 | |
|---|
| 203 | <a href="#add_word" id="add_word">Add more</a> |
|---|
| 204 | </div> |
|---|
| 205 | |
|---|
| 206 | <!-- Options --> |
|---|
| 207 | <div class="section" id="section_options"> |
|---|
| 208 | <?php if(isset($campaign_edit)): ?> |
|---|
| 209 | <div class="section_warn"> |
|---|
| 210 | <img src="<?php echo $arSettings->tplpath ?>/images/icon_alert.gif" alt="Warning" class="icon" /> |
|---|
| 211 | <h3>Remember that</h3> |
|---|
| 212 | <p>Changing these options only affects the creation of posts after the next time feeds are parsed.</p> |
|---|
| 213 | <p>If you need to edit existing posts, you can do so by using the options under the Tools tab</p> |
|---|
| 214 | </div> |
|---|
| 215 | <?php endif ?> |
|---|
| 216 | |
|---|
| 217 | <div class="checkbox"> |
|---|
| 218 | <label for="campaign_templatechk">Custom post template</label> |
|---|
| 219 | <?php echo checkbox_tag('campaign_templatechk', 1, _data_value($data['main'], 'template')) ?> |
|---|
| 220 | |
|---|
| 221 | <div id="post_template" class="textarea <?php if(_data_value($data['main'], 'template', '{content}') !== '{content}') echo 'current' ?>"> |
|---|
| 222 | <?php echo textarea_tag('campaign_template', _data_value($data['main'], 'template', '{content}')) ?> |
|---|
| 223 | <a href="#" id="enlarge_link">Enlarge</a> |
|---|
| 224 | |
|---|
| 225 | <p class="note" id="tags_note"> |
|---|
| 226 | 'Valid tags: |
|---|
| 227 | </p> |
|---|
| 228 | <p id="tags_list"> |
|---|
| 229 | <span class="tag">{content}</span>, <span class="tag">{title}</span>, <span class="tag">{permalink}</span>, <span class="tag">{feedurl}</span>, <span class="tag">{feedtitle}</span>, <span class="tag">{feedlogo}</span>,<br /> <span class="tag">{campaigntitle}</span>, <span class="tag">{campaignid}</span>, <span class="tag">{campaignslug}</span> |
|---|
| 230 | </p> |
|---|
| 231 | </div> |
|---|
| 232 | |
|---|
| 233 | <p class="note">Read about <a href="<?php echo $arSettings->helpurl; ?>" class="help_link">post templates</a>, or check some <a href="<?php echo $arSettings->helpurl; ?>" class="help_link">examples</a> ?></p> |
|---|
| 234 | </div> |
|---|
| 235 | |
|---|
| 236 | <div class="multipletext"> |
|---|
| 237 | <?php |
|---|
| 238 | $f = _data_value($data['main'], 'frequency'); |
|---|
| 239 | |
|---|
| 240 | if($f) { |
|---|
| 241 | $frequency = WPOTools::calcTime($f); |
|---|
| 242 | } |
|---|
| 243 | else |
|---|
| 244 | $frequency = array(); |
|---|
| 245 | ?> |
|---|
| 246 | |
|---|
| 247 | <label>Frequency</label> |
|---|
| 248 | |
|---|
| 249 | <?php echo input_tag('campaign_frequency_d', _data_value($frequency, 'days', 1), 'size=2 maxlength=3')?> |
|---|
| 250 | d |
|---|
| 251 | |
|---|
| 252 | <?php echo input_tag('campaign_frequency_h', _data_value($frequency, 'hours', 5), 'size=2 maxlength=2')?> |
|---|
| 253 | h |
|---|
| 254 | |
|---|
| 255 | <?php echo input_tag('campaign_frequency_m', _data_value($frequency, 'minutes', 0), 'size=2 maxlength=2')?> |
|---|
| 256 | m |
|---|
| 257 | |
|---|
| 258 | <p class="note">How often should feeds be checked? (days, hours and minutes)</p> |
|---|
| 259 | </div> |
|---|
| 260 | |
|---|
| 261 | <div class="checkbox"> |
|---|
| 262 | <?php echo label_for('campaign_cacheimages', 'Cache images') ?> |
|---|
| 263 | <? // need to install timthumb folder to get the following working ?> |
|---|
| 264 | <?php // echo checkbox_tag('campaign_cacheimages', 1, _data_value($data['main'], 'cacheimages', is_writable($arSettings->cachepath))) ?> |
|---|
| 265 | <p class="note">Images will be stored in your server, instead of hotlinking from the original site. |
|---|
| 266 | <a href="helpurl image_caching" class="help_link">More</a></p> |
|---|
| 267 | </div> |
|---|
| 268 | |
|---|
| 269 | <div class="checkbox"> |
|---|
| 270 | <?php echo label_for('campaign_feeddate', 'Use feed date') ?> |
|---|
| 271 | <?php echo checkbox_tag('campaign_feeddate', 1, _data_value($data['main'], 'feeddate', false)) ?> |
|---|
| 272 | <p class="note">Use the original date from the post instead of the time the post is created by WP-o-Matic. |
|---|
| 273 | <a href="helpurl feed_date_option" class="help_link">More</a></p> |
|---|
| 274 | </div> |
|---|
| 275 | |
|---|
| 276 | <div class="checkbox"> |
|---|
| 277 | <?php echo label_for('campaign_dopingbacks', 'Perform pingbacks') ?> |
|---|
| 278 | <?php echo checkbox_tag('campaign_dopingbacks', 1, _data_value($data['main'], 'dopingbacks', false)) ?> |
|---|
| 279 | </div> |
|---|
| 280 | |
|---|
| 281 | <div class="radio"> |
|---|
| 282 | <label class="main">Type of post to create</label> |
|---|
| 283 | |
|---|
| 284 | <?php echo radiobutton_tag('campaign_posttype', 'new', !isset($data['main']['posttype']) || _data_value($data['main'], 'posttype') == 'new', 'id=type_new') ?> |
|---|
| 285 | <?php echo label_for('type_new', 'Published (New)') ?> |
|---|
| 286 | |
|---|
| 287 | <?php echo radiobutton_tag('campaign_posttype', 'pending', _data_value($data['main'], 'posttype') == 'pending', 'id=type_pending') ?> |
|---|
| 288 | <?php echo label_for('type_pending', 'Pending') ?> |
|---|
| 289 | </div> |
|---|
| 290 | |
|---|
| 291 | <div class="text"> |
|---|
| 292 | <?php echo label_for('campaign_author', 'Author:') ?> |
|---|
| 293 | <?php // echo select_tag('campaign_author', options_for_select($author_usernames, _data_value($data['main'], 'author', 'admin'))) ?> |
|---|
| 294 | <p class="note">The created posts will be assigned to this author.</p> |
|---|
| 295 | </div> |
|---|
| 296 | |
|---|
| 297 | <div class="text required"> |
|---|
| 298 | <?php echo label_for('campaign_max', 'Max items to create on each fetch') ?> |
|---|
| 299 | <?php echo input_tag('campaign_max', _data_value($data['main'], 'max', '10'), 'size=2 maxlength=3') ?> |
|---|
| 300 | <p class="note">Set it to 0 for unlimited. If set to a value, only the last X items will be selected, ignoring the older ones.</p> |
|---|
| 301 | </div> |
|---|
| 302 | |
|---|
| 303 | <div class="checkbox"> |
|---|
| 304 | <?php echo label_for('campaign_linktosource', 'Post title links to source?') ?> |
|---|
| 305 | <?php echo checkbox_tag('campaign_linktosource', 1, _data_value($data['main'], 'linktosource', false)) ?> |
|---|
| 306 | </div> |
|---|
| 307 | |
|---|
| 308 | <div class="radio"> |
|---|
| 309 | <label class="main">Discussion options:</label> |
|---|
| 310 | |
|---|
| 311 | <?php echo select_tag('campaign_commentstatus', |
|---|
| 312 | options_for_select( |
|---|
| 313 | array('open' => 'Open', |
|---|
| 314 | 'closed' => 'Closed', |
|---|
| 315 | 'registered_only' => 'Registered only' |
|---|
| 316 | ), _data_value($data['main'], 'comment_status', 'open'))) ?> |
|---|
| 317 | |
|---|
| 318 | <?php echo checkbox_tag('campaign_allowpings', 1, _data_value($data['main'], 'allowpings', true)) ?> |
|---|
| 319 | <?php echo label_for('campaign_allowpings', 'Allow pings') ?> |
|---|
| 320 | </div> |
|---|
| 321 | </div> |
|---|
| 322 | |
|---|
| 323 | <?php if($action == 'edit'): ?> |
|---|
| 324 | <!-- Tools --> |
|---|
| 325 | <div class="section" id="section_tools"> |
|---|
| 326 | <div class="buttons"> |
|---|
| 327 | <h3>Posts action</h3> |
|---|
| 328 | <p class="note">The selected action applies to all the posts created by this campaign</p> |
|---|
| 329 | |
|---|
| 330 | <ul> |
|---|
| 331 | <li> |
|---|
| 332 | <div class="btn"> |
|---|
| 333 | <input type="submit" name="tool_removeall" value="Remove all" /> |
|---|
| 334 | </div> |
|---|
| 335 | </li> |
|---|
| 336 | <li> |
|---|
| 337 | <div class="radio"> |
|---|
| 338 | <label class="main">Change status to:</label> |
|---|
| 339 | |
|---|
| 340 | <input type="radio" name="campaign_tool_changetype" value="new" id="changetype_new" checked="checked" /> <label for="changetype_new">New</label> |
|---|
| 341 | <input type="radio" name="campaign_tool_changetype" value="private" id="changetype_private" /> <label for="changetype_private">Private</label> |
|---|
| 342 | <input type="radio" name="campaign_tool_changetype" value="draft" id="changetype_draft" /> <label for="changetype_draft">Draft</label> |
|---|
| 343 | <input type="submit" name="tool_changetype" value="Change" /> |
|---|
| 344 | </div> |
|---|
| 345 | </li> |
|---|
| 346 | <li> |
|---|
| 347 | <div class="text"> |
|---|
| 348 | <label for="campaign_tool_changeauthor">Change author username to:</label> |
|---|
| 349 | <?php echo select_tag('campaign_tool_changeauthor', options_for_select($author_usernames, _data_value($data['main'], 'author', 'admin'))) ?> |
|---|
| 350 | |
|---|
| 351 | <input type="submit" name="tool_changeauthor" value="Change" /> |
|---|
| 352 | </div> |
|---|
| 353 | </li> |
|---|
| 354 | </ul> |
|---|
| 355 | </div> |
|---|
| 356 | |
|---|
| 357 | <!-- |
|---|
| 358 | <div class="btn"> |
|---|
| 359 | <label>Test all feeds</label> |
|---|
| 360 | <input type="button" name="campaign_tool_testall_btn" value="Test" /> |
|---|
| 361 | <p class="note">This option creates one draft from each feed you added.</p> |
|---|
| 362 | </div> |
|---|
| 363 | --> |
|---|
| 364 | </div> |
|---|
| 365 | <?php endif; ?> |
|---|
| 366 | </div> |
|---|
| 367 | |
|---|
| 368 | </form> |
|---|
| 369 | |
|---|
| 370 | |
|---|
| 371 | |
|---|
| 372 | <?php |
|---|
| 373 | |
|---|
| 374 | }; ?> |
|---|
| 375 | |
|---|
| 376 | </div> |
|---|
| 377 | |
|---|
| 378 | <script type='text/javascript'> |
|---|
| 379 | jQuery('document').ready(function($) { |
|---|
| 380 | |
|---|
| 381 | //$("#tab_container .tab_content").hide(); //Hide all content |
|---|
| 382 | $("ul.tabs li:first").addClass("active").show(); //Activate first tab |
|---|
| 383 | $(".tab_content:first").show(); //Show first tab content |
|---|
| 384 | |
|---|
| 385 | //On Click Event |
|---|
| 386 | $("#admin_plugin_tabs ul.tabs li").click(function() { |
|---|
| 387 | //alert('hi'); |
|---|
| 388 | $("ul.tabs li").removeClass("active"); //Remove any "active" class |
|---|
| 389 | $(this).addClass("active"); //Add "active" class to selected tab |
|---|
| 390 | $(".section").hide(); //Hide all tab content |
|---|
| 391 | |
|---|
| 392 | var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content |
|---|
| 393 | $(activeTab).show(); //Fade in the active ID content |
|---|
| 394 | return false; |
|---|
| 395 | }); |
|---|
| 396 | }); |
|---|
| 397 | |
|---|
| 398 | $("#edit_submit").click(function(event) { |
|---|
| 399 | event.preventDefault(); |
|---|
| 400 | |
|---|
| 401 | // Save via AJAX |
|---|
| 402 | //var item_uid = $('.post').attr('id'); |
|---|
| 403 | // item_uid = item_uid.split('-'); |
|---|
| 404 | // item_uid = item_uid[item_uid.length-1]; // this gets the id of the post from the class that WP adds in, gets last element on post id |
|---|
| 405 | |
|---|
| 406 | var campaign = $("form#edit_campaign").serialize(); |
|---|
| 407 | |
|---|
| 408 | // campaign = $.URLEncode(campaign); |
|---|
| 409 | var formdata = campaign + "&action=save"; |
|---|
| 410 | var sendurl = BASEURL + 'admin_index.php?page=plugin_settings&plugin=autoreader&alt_template=autoreader_add'; |
|---|
| 411 | |
|---|
| 412 | $.ajax( |
|---|
| 413 | { |
|---|
| 414 | type: 'post', |
|---|
| 415 | url: sendurl, |
|---|
| 416 | data: formdata, |
|---|
| 417 | beforeSend: function () { |
|---|
| 418 | $('#edit_buttons').append('<img src="' + BASEURL + "content/admin_themes/" + ADMIN_THEME + 'images/ajax-loader.gif' + '"/>'); |
|---|
| 419 | }, |
|---|
| 420 | error: function(XMLHttpRequest, textStatus, errorThrown) { |
|---|
| 421 | //widget.html('ERROR'); |
|---|
| 422 | }, |
|---|
| 423 | success: function(data, textStatus) { // success means it returned some form of json code to us. may be code with custom error msg |
|---|
| 424 | if (data.error === true) { |
|---|
| 425 | } |
|---|
| 426 | else |
|---|
| 427 | { |
|---|
| 428 | var img_src = ""; |
|---|
| 429 | // get required image based on returned data showing new status |
|---|
| 430 | if(data.enabled == 'true') { img_src = "active.png"; } else { img_src = "inactive.png"; } |
|---|
| 431 | $('#edit_buttons').html('<img src="' + BASEURL + "content/admin_themes/" + ADMIN_THEME + 'images/' + img_src + '"/>'); |
|---|
| 432 | } |
|---|
| 433 | //$('#return_message').html(data.message).addClass(data.color); |
|---|
| 434 | //$('#return_message').html(data.message).addClass('message'); |
|---|
| 435 | //$('#return_message').fadeIn(1000).fadeout(1000); |
|---|
| 436 | }, |
|---|
| 437 | dataType: "json" |
|---|
| 438 | }); |
|---|
| 439 | |
|---|
| 440 | |
|---|
| 441 | return false; |
|---|
| 442 | |
|---|
| 443 | }); |
|---|
| 444 | |
|---|
| 445 | |
|---|
| 446 | function toSlug(str) { |
|---|
| 447 | return str.replace(/\W/g, ' ').replace(/\ +/g, '-').replace(/\-$/g, '').replace(/^\-/g, '').toLowerCase(); |
|---|
| 448 | } |
|---|
| 449 | |
|---|
| 450 | |
|---|
| 451 | // Basic tab |
|---|
| 452 | $('#campaign_title').keyup(function() { |
|---|
| 453 | // alert($('#campaign_title').val().replace(/ /g,'_')); |
|---|
| 454 | $('#campaign_slug').val(toSlug( $('#campaign_title').val())); |
|---|
| 455 | }); |
|---|
| 456 | |
|---|
| 457 | |
|---|
| 458 | // Feeds tab |
|---|
| 459 | |
|---|
| 460 | //- Test feed links |
|---|
| 461 | function check_feed(feed) { |
|---|
| 462 | feed.addClass('input_text'); |
|---|
| 463 | if(feed.val().length > 0) |
|---|
| 464 | { |
|---|
| 465 | var formdata = "url=" + feed.val()+ "&action=test_feed"; |
|---|
| 466 | var sendurl = BASEURL + 'admin_index.php?page=plugin_settings&plugin=autoreader&alt_template=autoreader_add'; |
|---|
| 467 | |
|---|
| 468 | $.ajax( |
|---|
| 469 | { |
|---|
| 470 | type: 'post', |
|---|
| 471 | url: sendurl, |
|---|
| 472 | data: formdata, |
|---|
| 473 | beforeSend: function () { |
|---|
| 474 | feed.addClass('green'); |
|---|
| 475 | }, |
|---|
| 476 | error: function(XMLHttpRequest, textStatus, errorThrown) { |
|---|
| 477 | feed.addClass('red'); |
|---|
| 478 | feed.val("Error occured"); |
|---|
| 479 | }, |
|---|
| 480 | success: function(data, textStatus) { // success means it returned some form of json code to us. may be code with custom error msg |
|---|
| 481 | if (data.result === 'fail') { |
|---|
| 482 | feed.addClass('red'); |
|---|
| 483 | feed.val(data.error); |
|---|
| 484 | } |
|---|
| 485 | else |
|---|
| 486 | { |
|---|
| 487 | feed.addClass('green'); |
|---|
| 488 | feed.val(data.url); |
|---|
| 489 | } |
|---|
| 490 | }, |
|---|
| 491 | dataType: "json" |
|---|
| 492 | }); |
|---|
| 493 | }; |
|---|
| 494 | feed.addClass('load input_text'); |
|---|
| 495 | }; |
|---|
| 496 | |
|---|
| 497 | |
|---|
| 498 | function update_feeds() { |
|---|
| 499 | $('#edit_feed div input[type=text]').focus(function() { |
|---|
| 500 | $(this).addClass('input_text').addClass('red'); |
|---|
| 501 | }); |
|---|
| 502 | |
|---|
| 503 | $('#edit_feed div input[type=text]').blur(function() { |
|---|
| 504 | check_feed($(this)); |
|---|
| 505 | $(this).removeClass('red'); |
|---|
| 506 | //alert('leave'); |
|---|
| 507 | }); |
|---|
| 508 | }; |
|---|
| 509 | |
|---|
| 510 | update_feeds(); |
|---|
| 511 | |
|---|
| 512 | |
|---|
| 513 | |
|---|
| 514 | |
|---|
| 515 | </script> |
|---|
| 516 | |
|---|
| 517 | |
|---|
| 518 | |
|---|