| 46 | | |
| 47 | | /** |
| 48 | | * Calls external site to get latest available hotaru version number |
| 49 | | * |
| 50 | | * @return string versionnumber |
| 51 | | */ |
| 52 | | public function hotaru_version($h) |
| 53 | | { |
| 54 | | $info = $this->sendApiRequest($h, array( |
| 55 | | 'api_key' => '', |
| 56 | | 'format' => 'json', |
| 57 | | 'method' => 'hotaru.version.get' |
| 58 | | )); |
| 59 | | |
| 60 | | // save the updated version number to the local db so we can display it on the admin panel until it gets updated. |
| 61 | | if (isset($info['version'])) { |
| 62 | | |
| 63 | | $sql = "SELECT miscdata_id FROM ".TABLE_MISCDATA." WHERE miscdata_key = %s"; |
| 64 | | $query = $h->db->get_row($h->db->prepare($sql, 'hotaru_latest_version')); |
| 65 | | |
| 66 | | $sql = ($query) ? |
| 67 | | "UPDATE ".TABLE_MISCDATA." SET miscdata_value = %s WHERE miscdata_key = %s" : |
| 68 | | "INSERT INTO ".TABLE_MISCDATA." (miscdata_value, miscdata_key) VALUES (%s, %s)"; |
| 69 | | |
| 70 | | $h->db->query($h->db->prepare($sql, $info['version'], 'hotaru_latest_version')); |
| 71 | | |
| 72 | | return $info['version']; |
| 73 | | } |
| 74 | | |
| 75 | | return 0; |
| 76 | | } |
| 77 | | |
| 78 | | /** |
| 79 | | * Calls external site to get latest available hotaru version number |
| 80 | | * |
| 81 | | * @return bool true |
| 82 | | */ |
| 83 | | public function plugin_version_getAll($h) |
| 84 | | { |
| 85 | | $info = $this->sendApiRequest($h, array( |
| 86 | | 'api_key' => '', |
| 87 | | 'format' => 'json', |
| 88 | | 'method' => 'hotaru.plugin.version.getAll' |
| 89 | | )); |
| 90 | | |
| 91 | | if ($info) { |
| 92 | | // save the updated version numbers to the local db so we can display it on the plugin management panel |
| 93 | | $sql = "SELECT plugin_id, plugin_name, plugin_version, plugin_latestversion FROM ".TABLE_PLUGINS; |
| 94 | | $plugins = $h->db->get_results($h->db->prepare($sql)); |
| 95 | | if ($plugins) { |
| 96 | | foreach ($plugins as $plugin) { |
| 97 | | if (array_key_exists($plugin->plugin_name, $info)) { |
| 98 | | $sql = "UPDATE ".TABLE_PLUGINS." SET plugin_latestversion = %s WHERE (plugin_id = %d)"; |
| 99 | | $h->db->query($h->db->prepare($sql, $info[$plugin->plugin_name], $plugin->plugin_id)); |
| 100 | | } |
| 101 | | if($plugin->plugin_version > $plugin->plugin_latestversion) |
| 102 | | { |
| 103 | | $sql = "UPDATE ".TABLE_PLUGINS." SET plugin_latestversion = %s WHERE (plugin_id = %d)"; |
| 104 | | $h->db->query($h->db->prepare($sql, $plugin->plugin_version, $plugin->plugin_id)); |
| 105 | | } |
| 106 | | } |
| 107 | | } |
| 108 | | } |
| 109 | | |
| 110 | | return TRUE; |
| 111 | | } |
| 112 | | |
| 113 | | |
| 114 | | /** |
| 115 | | * |
| 116 | | * @param <type> $search |
| 117 | | */ |
| 118 | | public function pluginSearch($h, $search) |
| 119 | | { |
| 120 | | return $this->sendApiRequest($h, array( |
| 121 | | 'api_key' => '', |
| 122 | | 'format' => 'json', |
| 123 | | 'method' => 'hotaru.plugin.search', |
| 124 | | 'args' => $search |
| 125 | | )); |
| 126 | | } |
| 127 | | |
| 128 | | /** |
| 129 | | * |
| 130 | | */ |
| 131 | | public function pluginTagCloud($h, $number = 20) |
| 132 | | { |
| 133 | | return $this->sendApiRequest($h, array( |
| 134 | | 'api_key' => '', |
| 135 | | 'format' => 'json', |
| 136 | | 'method' => 'hotaru.plugin.tagcloud', |
| 137 | | 'args' => $number |
| 138 | | )); |
| 139 | | } |