| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking - Libraries |
| 4 |
* @subpackage update |
| 5 |
* @author E4J s.r.l. |
| 6 |
* @copyright Copyright (C) 2018 E4J s.r.l. All Rights Reserved. |
| 7 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
// No direct access |
| 12 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 13 |
|
| 14 |
/** |
| 15 |
* Class used to handle the software changelog. |
| 16 |
* |
| 17 |
* @since 1.0 |
| 18 |
*/ |
| 19 |
class VikBookingChangelog |
| 20 |
{ |
| 21 |
/** |
| 22 |
* Builds the changelog previously stored. |
| 23 |
* |
| 24 |
* @return string the parsed HTML code of the changelog |
| 25 |
* |
| 26 |
* @uses getTree() |
| 27 |
*/ |
| 28 |
public static function build() |
| 29 |
{ |
| 30 |
$tree = self::getTree(); |
| 31 |
|
| 32 |
if (empty($tree)) |
| 33 |
{ |
| 34 |
return ''; |
| 35 |
} |
| 36 |
|
| 37 |
$changelog = ''; |
| 38 |
|
| 39 |
foreach ($tree as $versionlog) |
| 40 |
{ |
| 41 |
// open version |
| 42 |
$file = JHtml::fetch('layoutfile', 'html.changelog.version.open'); |
| 43 |
$changelog .= $file->render(array( |
| 44 |
'title' => $versionlog->title, |
| 45 |
'version' => $versionlog->version |
| 46 |
)); |
| 47 |
|
| 48 |
// parse the sections of this version changelog |
| 49 |
foreach ($versionlog->sections as $section) |
| 50 |
{ |
| 51 |
// open section |
| 52 |
$file = JHtml::fetch('layoutfile', 'html.changelog.section.open'); |
| 53 |
$changelog .= $file->render(array( |
| 54 |
'title' => $section->title |
| 55 |
)); |
| 56 |
|
| 57 |
// parse the children of this section |
| 58 |
foreach ($section->children as $feature) |
| 59 |
{ |
| 60 |
// feature item |
| 61 |
$file = JHtml::fetch('layoutfile', 'html.changelog.feature.item'); |
| 62 |
$changelog .= $file->render(array( |
| 63 |
'title' => $feature->title, |
| 64 |
'descr' => $feature->description |
| 65 |
)); |
| 66 |
} |
| 67 |
|
| 68 |
// close section |
| 69 |
$file = JHtml::fetch('layoutfile', 'html.changelog.section.close'); |
| 70 |
$changelog .= $file->render(); |
| 71 |
} |
| 72 |
|
| 73 |
// close version |
| 74 |
$file = JHtml::fetch('layoutfile', 'html.changelog.version.close'); |
| 75 |
$changelog .= $file->render(); |
| 76 |
} |
| 77 |
|
| 78 |
return $changelog; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Returns the current changelog tree object |
| 83 |
* |
| 84 |
* @return mixed string if empty, object otherwise |
| 85 |
*/ |
| 86 |
public static function getTree() |
| 87 |
{ |
| 88 |
$changelog = get_option('vikbooking_changelog', ''); |
| 89 |
|
| 90 |
return !empty($changelog) ? json_decode($changelog) : ''; |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Stores the returned changelog for the current version in JSON. |
| 95 |
* If no change-log for the current version, the old value is unset. |
| 96 |
* |
| 97 |
* @param object $tree the changelog tree object |
| 98 |
* |
| 99 |
* @return void |
| 100 |
*/ |
| 101 |
public static function store($tree) |
| 102 |
{ |
| 103 |
$changelog = ''; |
| 104 |
|
| 105 |
if (!empty($tree)) |
| 106 |
{ |
| 107 |
$changelog = json_encode($tree); |
| 108 |
} |
| 109 |
|
| 110 |
update_option('vikbooking_changelog', $changelog); |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Registers options upon installation of the plugin. |
| 115 |
* |
| 116 |
* @return void |
| 117 |
*/ |
| 118 |
public static function install() |
| 119 |
{ |
| 120 |
update_option('vikbooking_changelog', ''); |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Deletes options upon uninstallation of the plugin. |
| 125 |
* |
| 126 |
* @return void |
| 127 |
*/ |
| 128 |
public static function uninstall() |
| 129 |
{ |
| 130 |
delete_option('vikbooking_changelog'); |
| 131 |
} |
| 132 |
} |
| 133 |
|