forked from Simounet/LeedSmartFeedsUpdate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smartfeedsupdate.plugin.php
137 lines (118 loc) · 5.13 KB
/
smartfeedsupdate.plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/*
@name LeedSmartFeedsUpdate
@author Simounet <[email protected]>
@link http://www.simounet.net
@licence MIT
@version 1.0.0
@description Better feeds update handler
*/
require_once( __DIR__ . "/classes/SmartFeedsUpdate.php" );
function add_synchro_option( $synchronisationType ) {
$identifier = SmartFeedsUpdate::SYNC_TYPE_NAME;
$checked = false;
if( $synchronisationType == $identifier ) {
$checked = 'checked="checked"';
}
echo
'<p>' .
'<input
type="radio"
id="synchronisationType' . $identifier . '"
name="synchronisationType"
value="' . $identifier . '" ' .
$checked .
'> '.
'<label
for="synchronisationType' . $identifier .'">' .
'<strong>' . _t('SMARTFEEDSUPDATE_SMART') . ' :</strong>' .
'</label> ' . _t('SMARTFEEDSUPDATE_SMART_DESC') .
'</p>';
}
function get_feeds( &$synchronisation_custom, &$synchronisationType, &$commandLine, $configurationManager, $start ) {
require_once( __DIR__ . "/classes/SmartFeedsUpdateFeeds.php" );
$update_feeds = new SmartFeedsUpdateFeeds();
if( $synchronisationType == $update_feeds::SYNC_TYPE_NAME ) {
$synchronisation_custom['no_normal_synchronize'] = true;
require_once( __DIR__ . "/classes/ExtendedFeed.php" );
$update_feeds->updateFeeds( $commandLine, $configurationManager, $start );
}
}
function setSmartFeedsUpdateSettingsLink( &$my_user ) {
echo '<li><a class="toggle" href="#smartFeedsUpdateSettingsBlock">'._t('SMARTFEEDSUPDATE_SETTINGS').'</a></li>';
}
function setSmartFeedsUpdateSettingsBlock( &$my_user, &$feeds ) {
Plugin::addJs( '/js/script.js' );
$update_feeds = new SmartFeedsUpdate();
$slots = $update_feeds->populate();
echo '<section class="smartFeedsUpdateSettingsBlock" style="display:none;">';
echo '<form id="smartupdate-form" action="/action.php" method="post">';
echo '<h2>' . _t( 'SMARTFEEDSUPDATE_SETTINGS' ) . '</h2>';
echo '<p>' . _t( 'SMARTFEEDSUPDATE_FREQUENCY_NOTIFICATION' ) . '</p>';
foreach( $slots as $slot ) {
$slot_id = $slot->getSlot();
$slot_id_nice = $update_feeds->getNiceSlotIdString( $slot_id );
echo '<section class="addBloc">';
echo '<h3>' . $slot_id_nice . ' (' . date('H:i m/d/Y', $slot->getNextUpdate()) . ')</h3>';
echo '<ul class="nochip">';
// [facto] - Not very efficient...
// I have to build a request with feeds' names and id
// Then merge infos avoiding me the feeds foreachs
$feed_id_array = $slot->getFeedIdArray();
if( is_array( $feed_id_array ) ) {
foreach( $feed_id_array as $id ) {
foreach( $feeds as $feed ) {
$feed_id = $feed->getId();
if( $id == $feed_id ) {
echo '<li>';
echo '<span class="feedTitle">' . Functions::truncate( $feed->getName(), 30 ) . '</span>';
echo '<select class="js-smart-feeds-update-select" name="smartupdates" data-feed-id="' . $feed_id . '">';
foreach( $update_feeds->slots_default as $slot ) {
$slot_nice = $update_feeds->getNiceSlotIdString( $slot );
$selected = $slot == $slot_id ? ' selected' : false;
echo '<option value="' . $slot . '"' . $selected . '>' . $slot_nice . '</option>';
}
echo '</select>';
echo '</li>';
}
}
}
}
echo '</ul>';
echo '</section>';
}
echo '</form>';
echo '</section>';
}
function setSmartFeedsUpdateFeedSlot( &$_, $myUser ) {
if(
! isset( $_['feed-id'] )
|| ! isset( $_['previous-slot'] )
|| ! isset( $_['new-slot'] )
) {
return false;
}
$update_feeds = new SmartFeedsUpdate();
$update_feeds->updateFeed( $_['feed-id'], $_['previous-slot'], $_['new-slot'] );
//header('location: ./settings.php');
header('Location: '.$_SERVER['PHP_SELF']);
die;
}
function smartFeedsUpdateAddFeed( &$newFeed ) {
require_once( __DIR__ . "/classes/SmartFeedsUpdateFrequencies.php" );
$smart_update = new SmartFeedsUpdateFrequencies();
$smart_update->addFeedFrequency( $newFeed );
}
function smartFeedsUpdateRemoveFeed( $feedId ) {
require_once( __DIR__ . "/classes/SmartFeedsUpdateFrequencies.php" );
$smart_update = new SmartFeedsUpdateFrequencies();
$smart_update->removeFeedFrequency( $feedId );
}
Plugin::addHook( "setting_post_synchronisation_options", "add_synchro_option" );
Plugin::addHook( "action_before_synchronisationtype", "get_feeds" );
Plugin::addHook( "setting_post_link", "setSmartFeedsUpdateSettingsLink" );
Plugin::addHook( "setting_post_section", "setSmartFeedsUpdateSettingsBlock" );
Plugin::addHook( "action_post_case", "setSmartFeedsUpdateFeedSlot" );
Plugin::addHook( "action_after_addFeed", "smartFeedsUpdateAddFeed" );
Plugin::addHook( "action_after_removeFeed", "smartFeedsUpdateRemoveFeed" );
?>