public static function latest_available() { $list = theme::list_available(); $post = array(); if (!is_array($list)) { return false; } foreach ($list as $theme) { $post[$theme['code']] = $theme['version']; } $latest_update = core_curl_post('http://update.navigatecms.com/themes', array('themes' => json_encode($post))); if (empty($latest_update)) { return false; } $latest_update = json_decode($latest_update, true); return $latest_update; }
function run() { global $user; global $layout; global $website; global $theme; global $DB; $out = ''; switch ($_REQUEST['act']) { case 'theme_info': echo '<iframe src="' . NAVIGATE_URL . '/themes/' . $_REQUEST['theme'] . '/' . $_REQUEST['theme'] . '.info.html' . '" scrolling="auto" frameborder="0" width="100%" height="100%"></iframe>'; core_terminate(); break; case 'remove': // check the theme is not actually used in any website $usages = $DB->query_single('COUNT(*)', 'nv_websites', ' theme = ' . protect($_REQUEST['theme'])); if ($usages == 0) { try { $theme = new theme(); $theme->load($_REQUEST['theme']); $status = $theme->delete(); echo json_encode($status); } catch (Exception $e) { echo $e->getMessage(); } } else { $status = t(537, "Can't remove the theme because it is currently being used by another website."); echo $status; } core_terminate(); break; /* case 'export': $out = themes_export_form(); break; */ /* case 'export': $out = themes_export_form(); break; */ case 'theme_sample_content_import': try { $theme->import_sample(); $layout->navigate_notification(t(374, "Item installed successfully."), false); } catch (Exception $e) { $layout->navigate_notification($e->getMessage(), true, true); } $themes = theme::list_available(); $out = themes_grid($themes); break; case 'theme_sample_content_export': if (empty($_POST)) { $out = themes_sample_content_export_form(); } else { $categories = explode(',', $_POST['categories']); $folder = $_POST['folder']; $items = explode(',', $_POST['elements']); $block_groups = explode(',', $_POST['block_groups']); $blocks = explode(',', $_POST['blocks']); $comments = explode(',', $_POST['comments']); theme::export_sample($categories, $items, $block_groups, $blocks, $comments, $folder); core_terminate(); } break; case 'install_from_hash': $url = base64_decode($_GET['hash']); if (!empty($url) && $user->permission("themes.install") == "true") { $error = false; parse_str(parse_url($url, PHP_URL_QUERY), $query); $tmp_file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $query['code'] . '.zip'; @core_file_curl($url, $tmp_file); if (@filesize($tmp_file) == 0) { @unlink($tmp_file); // core file curl failed, try using file_get_contents... $tmp = @file_get_contents($url); if (!empty($tmp)) { @file_put_contents($tmp_file, $tmp); } unset($tmp); } if (@filesize($tmp_file) > 0) { // uncompress ZIP and copy it to the themes dir @mkdir(NAVIGATE_PATH . '/themes/' . $query['code']); $zip = new ZipArchive(); $zip_open_status = $zip->open($tmp_file); if ($zip_open_status === TRUE) { $zip->extractTo(NAVIGATE_PATH . '/themes/' . $query['code']); $zip->close(); $layout->navigate_notification(t(374, "Item installed successfully."), false); } else { $layout->navigate_notification('ERROR ' . $zip_open_status, true, true); $error = true; } } else { $layout->navigate_notification(t(56, 'Unexpected error'), true, true); $error = true; } if ($error) { $layout->add_content(' <div id="navigate_marketplace_install_from_hash_error"> <p>' . t(529, "It has not been possible to download the item you have just bought from the marketplace.") . '</p> <p>' . t(530, "You have to visit your Marketplace Dashboard and download the file, then use the <strong>Install from file</strong> button you'll find in the actions bar on the right.") . '</p> <p>' . t(531, "Sorry for the inconvenience.") . '</p> <a class="uibutton" href="http://www.navigatecms.com/en/marketplace/dashboard" target="_blank"><span class="ui-icon ui-icon-extlink" style="float: left;"></span> ' . t(532, "Navigate CMS Marketplace") . '</a> </div> '); $layout->add_script(' $("#navigate_marketplace_install_from_hash_error").dialog({ modal: true, title: "' . t(56, "Unexpected error") . '" }); '); } } // don't break, we want to show the themes grid right now (theme_upload by browser upload won't trigger) // don't break, we want to show the themes grid right now (theme_upload by browser upload won't trigger) case 'theme_upload': if (isset($_FILES['theme-upload']) && $_FILES['theme-upload']['error'] == 0 && $user->permission("themes.install") == "true") { // uncompress ZIP and copy it to the themes dir $tmp = trim(substr($_FILES['theme-upload']['name'], 0, strpos($_FILES['theme-upload']['name'], '.'))); $theme_name = filter_var($tmp, FILTER_SANITIZE_EMAIL); if ($tmp != $theme_name) { $layout->navigate_notification(t(344, 'Security error'), true, true); } else { @mkdir(NAVIGATE_PATH . '/themes/' . $theme_name); $zip = new ZipArchive(); if ($zip->open($_FILES['theme-upload']['tmp_name']) === TRUE) { $zip->extractTo(NAVIGATE_PATH . '/themes/' . $theme_name); $zip->close(); $layout->navigate_notification(t(374, "Item installed successfully."), false); } else { $layout->navigate_notification(t(262, 'Error uploading file'), true, true); } } } // don't break, we want to show the themes grid right now // don't break, we want to show the themes grid right now case 'themes': default: if (@$_REQUEST['opt'] == 'install') { $ntheme = new theme(); $ntheme->load($_REQUEST['theme']); $website->theme = $ntheme->name; if (!empty($ntheme->styles)) { $nst = get_object_vars($ntheme->styles); $nst = array_keys($nst); if (!isset($website->theme_options) || empty($website->theme_options)) { $website->theme_options = json_decode('{"style": ""}'); } $website->theme_options->style = array_shift($nst); } else { if (!isset($website->theme_options) || empty($website->theme_options)) { $website->theme_options = json_decode('{"style": ""}'); } else { $website->theme_options->style = ""; } } try { $website->update(); $layout->navigate_notification(t(374, "Item installed successfully."), false); } catch (Exception $e) { $layout->navigate_notification($e->getMessage(), true, true); } } $themes = theme::list_available(); $out = themes_grid($themes); break; } return $out; }