| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* |
| 8 |
*/ |
| 9 |
class CJTStoreUpdate { |
| 10 |
|
| 11 |
/** |
| 12 |
* put your comment there... |
| 13 |
* |
| 14 |
* @var mixed |
| 15 |
*/ |
| 16 |
private $store; |
| 17 |
|
| 18 |
/** |
| 19 |
* put your comment there... |
| 20 |
* |
| 21 |
* @param mixed $name |
| 22 |
* @param mixed $license |
| 23 |
* @param mixed $pluginFile |
| 24 |
* @return CJTStoreUpdate |
| 25 |
*/ |
| 26 |
public function __construct($name, $license, $pluginFile) { |
| 27 |
# Interact with store |
| 28 |
$this->store = new CJTStore( $name, $license, $pluginFile ); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* put your comment there... |
| 33 |
* |
| 34 |
*/ |
| 35 |
public function _connectErrorAdminNotice() { |
| 36 |
# Create DOm Document |
| 37 |
$message = new DOMDocument(); |
| 38 |
$message->loadXML('<span><div><p></p></div></span>'); |
| 39 |
# Create notice element |
| 40 |
$rootElement = $message->documentElement; |
| 41 |
$notice = $rootElement->childNodes->item( 0 ); |
| 42 |
$notice->setAttribute( 'class', 'error' ); |
| 43 |
$notice->childNodes->item( 0 )->nodeValue = 'Unable to fetch update! CJT Store unavailable!'; |
| 44 |
echo $message->saveHTML(); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* put your comment there... |
| 49 |
* |
| 50 |
* @param mixed $data |
| 51 |
* @param mixed $action |
| 52 |
* @param mixed $args |
| 53 |
*/ |
| 54 |
public function _overridePluginInformation($data, $action, $args) { |
| 55 |
# Act only with plugins_information action |
| 56 |
switch ( $action ) { |
| 57 |
case 'plugin_information' : |
| 58 |
# INitialize |
| 59 |
$store =& $this->getStore(); |
| 60 |
# Try to Get Plugin information |
| 61 |
try { |
| 62 |
$pluginInfo = $store->getPluginInformation(); |
| 63 |
$pluginData = get_plugin_data( $store->getPluginFile() ); |
| 64 |
# Make sure the requested Plugin is the one |
| 65 |
# associated with this object |
| 66 |
if ( $args && $args->slug && ( $this->getStore()->getSlug() == $args->slug ) ) { |
| 67 |
# Fill Plugin information data and return it back |
| 68 |
$data = (object) array( |
| 69 |
'version' => $pluginInfo[ 'currentVersion' ], |
| 70 |
'last_updated' => $pluginInfo[ 'lastUpdated' ], |
| 71 |
'author' => $pluginData[ 'Author' ], |
| 72 |
'requires' => $pluginInfo[ 'requires' ], |
| 73 |
'tested' => $pluginInfo[ 'tested' ], |
| 74 |
'homepage' => $pluginInfo[ 'url' ], |
| 75 |
'downloaded' => $pluginInfo[ 'downloadsCount' ], |
| 76 |
'slug' => $store->getSlug(), |
| 77 |
'name' => $pluginData[ 'Name' ], |
| 78 |
'sections' => array( |
| 79 |
'description' => $pluginInfo[ 'description' ], |
| 80 |
'installation' => $pluginInfo[ 'installation' ], |
| 81 |
'faq' => $pluginInfo[ 'faq' ], |
| 82 |
'screenshots' => $pluginInfo[ 'screenshots' ], |
| 83 |
'changelog' => $pluginInfo[ 'changeLog' ], |
| 84 |
'reviews' => $pluginInfo[ 'reviews' ], |
| 85 |
'other_notes' => $pluginInfo[ 'otherNotes' ] |
| 86 |
) |
| 87 |
); |
| 88 |
} |
| 89 |
} |
| 90 |
catch ( CJTServicesAPICallException $exception ) { |
| 91 |
# We will do nothing if CJT Store Server if not availabel |
| 92 |
# Just wait for subsequence requestes to get response!!! |
| 93 |
} |
| 94 |
break; |
| 95 |
} |
| 96 |
# Return either FALSE or plugin information if |
| 97 |
# the plugin is belongs to CJT store |
| 98 |
return $data; |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* put your comment there... |
| 103 |
* |
| 104 |
* @param mixed $transient |
| 105 |
*/ |
| 106 |
public function _transientPluginUpdate($transient) { |
| 107 |
# INitialize |
| 108 |
$store =& $this->getStore(); |
| 109 |
try { |
| 110 |
# Try to get Plugin update |
| 111 |
$pluginUpdate = $store->hasUpdate(); |
| 112 |
# Transient Plugin updaate if thereis new version |
| 113 |
if ( $pluginUpdate ) { |
| 114 |
# Get Plugin base name |
| 115 |
$pluginBaseName = plugin_basename( $store->getPluginFile() ); |
| 116 |
# Add to update list |
| 117 |
$transient->response[ $pluginBaseName ] = (object) array( |
| 118 |
'id' => null, |
| 119 |
'plugin' => $pluginBaseName, |
| 120 |
'slug' => basename( $pluginBaseName, '.php' ), |
| 121 |
'new_version' => $pluginUpdate[ 'currentVersion' ], |
| 122 |
'url' => $pluginUpdate[ 'url' ], |
| 123 |
'package' => $pluginUpdate[ 'package' ], |
| 124 |
); |
| 125 |
} |
| 126 |
} |
| 127 |
catch ( CJTServicesAPICallException $exception ) { |
| 128 |
# We will do nothing if CJT Store Server if not availabel |
| 129 |
# Just wait for subsequence requestes to get response!!! |
| 130 |
add_action( 'admin_notices', array( $this, '_connectErrorAdminNotice' ) ); |
| 131 |
} |
| 132 |
# Return transient array |
| 133 |
return $transient; |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* put your comment there... |
| 138 |
* |
| 139 |
* @param mixed $itemName |
| 140 |
* @param mixed $license |
| 141 |
* @param mixed $pluginFile |
| 142 |
*/ |
| 143 |
public static function & autoUpgrade($itemName, $license, $pluginFile) { |
| 144 |
# Get instance |
| 145 |
$instance = new CJTStoreUpdate( $itemName, $license, $pluginFile ); |
| 146 |
# Start update and return $instance |
| 147 |
return $instance->update(); |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* put your comment there... |
| 152 |
* |
| 153 |
*/ |
| 154 |
public function & getStore() { |
| 155 |
return $this->store; |
| 156 |
} |
| 157 |
|
| 158 |
/** |
| 159 |
* put your comment there... |
| 160 |
* |
| 161 |
*/ |
| 162 |
public function & update() { |
| 163 |
# Hook for adding CJT Extension to UPDATE Plugins list |
| 164 |
add_filter( 'pre_set_site_transient_update_plugins', array( $this, '_transientPluginUpdate' ) ); |
| 165 |
# Hook for displaying Plugin Information form |
| 166 |
add_filter( 'plugins_api', array( $this, '_overridePluginInformation' ), 10, 3 ); |
| 167 |
# Chain |
| 168 |
return $this; |
| 169 |
} |
| 170 |
|
| 171 |
} |