__construct(); } /** * Constructor of the class * * @return none */ public function __construct() { $this->init(); } /** * Function which initializes this class * * @return none */ public function init() { global $revisions_data; $this->cache_table = $revisions_data->get_all_last_revisions(); } /** * Function which updates some revision * * @param string $type plugin, theme or core * @param string $slug plugin or theme slug * @param string $name plugin or theme name * @param string $textdomain plugin or theme textdomain * @param string $version plugin, theme or core version * @param string $locale locale of this translation * @param int $revision revision of translation * @param int $percent percent of translation * @return bool success */ public function update_revision( $type, $slug, $name, $textdomain, $version, $locale, $revision, $percent ) { if ( 'core' == $type ) { if ( isset ( $this->cache_table[$type][$version][$locale]['revision'] ) ) { if ( $this->cache_table[$type][$version][$locale]['revision'] < $revision ) { $this->cache_table[$type][$version][$locale]['name'] = $name; $this->cache_table[$type][$version][$locale]['revision'] = $revision; $this->cache_table[$type][$version][$locale]['percent'] = $percent; return true; } } else return false; } else { if ( isset( $this->cache_table[$type][$slug][$version][$locale]['revision'] ) ) { if ( $this->cache_table[$type][$slug][$version][$locale]['revision'] < $revision ) { $this->cache_table[$type][$slug][$version][$locale]['name'] = $name; $this->cache_table[$type][$slug][$version][$locale]['textdomain'] = $textdomain; $this->cache_table[$type][$slug][$version][$locale]['revision'] = $revision; $this->cache_table[$type][$slug][$version][$locale]['percent'] = $percent; return true; } } else return false; } return false; } /** * Function which inserts some revision * * @param string $type plugin, theme or core * @param string $slug plugin or theme slug * @param string $name plugin or theme name * @param string $textdomain plugin or theme textdomain * @param string $version plugin, theme or core version * @param string $locale locale of this translation * @param int $revision revision of translation * @param int $percent percent of translation * @return bool success */ public function insert_revision( $type, $slug, $name, $textdomain, $version, $locale, $revision, $percent ) { if ( 'core' == $type ) { if ( !isset( $this->cache_table[$type][$version][$locale]['revision'] ) ) { $this->cache_table[$type][$version][$locale]['name'] = $name; $this->cache_table[$type][$version][$locale]['revision'] = $revision; $this->cache_table[$type][$version][$locale]['percent'] = $percent; return true; } } else { if ( ! isset( $this->cache_table[$type][$slug][$version][$locale]['revision'] ) ) { $this->cache_table[$type][$slug][$version][$locale]['name'] = $name; $this->cache_table[$type][$slug][$version][$locale]['textdomain'] = $textdomain; $this->cache_table[$type][$slug][$version][$locale]['revision'] = $revision; $this->cache_table[$type][$slug][$version][$locale]['percent'] = $percent; return true; } } return true; } /** * Function which returns some revision * * @param string $type plugin, theme or core * @param string $slug plugin or theme slug * @param string $version plugin, theme or core version * @param string $locale locale of this translation * @return bool success */ public function get_revision( $type, $slug, $version, $locale ) { $output['type'] = $type; $output['slug'] = $slug; $output['version'] = $version; $output['locale'] = $locale; if ( 'core' == $type ) { if ( isset( $this->cache_table[$type][$version][$locale]['revision'] ) ) { $output['revision'] = $this->cache_table[$type][$version][$locale]['revision']; $output['name'] = $this->cache_table[$type][$version][$locale]['name']; if ( isset( $this->cache_table[$type][$version][$locale]['percent'] ) ) { $output['percent'] = $this->cache_table[$type][$version][$locale]['percent']; } return $output; } } else { if ( isset( $this->cache_table[$type][$slug][$version][$locale]['revision'] ) ) { $output['revision'] = $this->cache_table[$type][$slug][$version][$locale]['revision']; $output['name'] = $this->cache_table[$type][$slug][$version][$locale]['name']; $output['textdomain'] = $this->cache_table[$type][$slug][$version][$locale]['textdomain']; if ( isset( $this->cache_table[$type][$slug][$version][$locale]['percent'] ) ) { $output['percent'] = $this->cache_table[$type][$slug][$version][$locale]['percent']; } return $output; } } return NULL; } /** * Function which deletes some revision * * @param string $type plugin, theme or core * @param string $slug plugin or theme slug * @param string $version plugin, theme or core version * @param string $locale locale of this translation * @return bool success */ public function delete_revision( $type, $slug, $version, $locale ) { if ( 'core' == $type ) { if ( !isset( $this->cache_table[$type][$version][$locale]['revision'] ) ) { unset( $this->cache_table[$type][$version][$locale] ); return true; } } else { if ( !isset( $this->cache_table[$type][$slug][$version][$locale]['revision'] ) ) { unset( $this->cache_table[$type][$slug][$version][$locale]['revision'] ); return true; } } return false; } } ?>