0, 'undocumented' => 0, 'total' => 0, 'percent' => 0.0); } $caps = AIEO_Capability_Registry::all(); $doc = 0; foreach ($caps as $id => $row) { if (self::get($id, $lang)) { $doc++; } } $total = count($caps); return array( 'documented' => $doc, 'undocumented' => $total - $doc, 'total' => $total, 'percent' => $total ? round($doc * 100 / $total, 1) : 0.0, ); } public static function stale($lang = 'en') { $out = array('stale' => array(), 'missing' => array()); if (!class_exists('AIEO_Capability_Registry')) { return $out; } $current = defined('AIEO_VERSION') ? AIEO_VERSION : '0'; foreach (AIEO_Capability_Registry::all() as $id => $row) { $rec = self::get($id, $lang); if (!$rec) { $out['missing'][] = array( 'id' => $id, 'label' => isset($row['label']) ? $row['label'] : $id, 'kind' => isset($row['kind']) ? $row['kind'] : '', ); continue; } $was = isset($rec['plugin_version']) ? (string) $rec['plugin_version'] : '0'; if (version_compare($was, $current, '<')) { $out['stale'][] = array( 'id' => $id, 'label' => isset($row['label']) ? $row['label'] : $id, 'kind' => isset($row['kind']) ? $row['kind'] : '', 'documented_at' => $was, 'current_version' => $current, 'url' => isset($rec['url']) ? $rec['url'] : '', ); } } return $out; } public static function for_action($action_id, $tab_id = '', $lang = 'en') { $action_id = (string) $action_id; if ($action_id === '') { return null; } $page = strpos($action_id, '.') !== false ? substr($action_id, 0, strpos($action_id, '.')) : ''; $tries = array( 'action' => 'action:' . $page . ':' . $action_id, ); if ($tab_id !== '' && $page !== '') { $tries['tab'] = 'tab:' . $page . ':' . $tab_id; } if ($page !== '') { $tries['page'] = $page; } foreach ($tries as $level => $cap_id) { $rec = self::get($cap_id, $lang); if ($rec) { return array_merge($rec, array('matched' => $level, 'capability' => $cap_id)); } } return null; } public static function summary($lang = 'en') { $c = self::coverage($lang); $s = self::stale($lang); return sprintf( __('%1$d of %2$d capabilities documented (%3$s%%); %4$d need re-publishing', 'ai-eshop-optimizer'), $c['documented'], $c['total'], $c['percent'], count($s['stale']) ); } }