source: branches/1.2/content/plugins/autoreader/templates/autoreader_add.php @ 1334

Revision 1334, 23.7 KB checked in by shibuya246, 3 years ago (diff)

[branch 1.2] latest changes for current version

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