public static function install_from_navigatecms($updates = array())
 {
     global $DB;
     @set_time_limit(0);
     if (empty($updates)) {
         $updates = update::updates_available();
     }
     if (empty($updates[0]['Revision'])) {
         return false;
     }
     $ulog = NAVIGATE_PATH . '/updates/update-' . $updates[0]['Revision'] . '.log.txt';
     file_put_contents($ulog, "UPDATE PROCESS " . $updates[0]['Revision'] . ' on ' . time() . "\n", FILE_APPEND);
     // download
     $ufile = NAVIGATE_PATH . '/updates/update-' . $updates[0]['Revision'] . '.zip';
     if (!file_exists($ufile) || filesize($ufile) < 1000) {
         file_put_contents($ulog, "download update...\n", FILE_APPEND);
         //$data = file_get_contents($updates[0]['Zip URL']);
         //file_put_contents($ufile, $data);
         @copy($updates[0]['Zip URL'], $ufile);
         if (!file_exists($ufile) || filesize($ufile) < 100) {
             // try to download update with curl
             core_file_curl($updates[0]['Zip URL'], $ufile);
         }
         file_put_contents($ulog, "update downloaded\n", FILE_APPEND);
     } else {
         file_put_contents($ulog, "update already downloaded\n", FILE_APPEND);
     }
     return update::install_from_file($updates[0]['Version'], $updates[0]['Revision'], $ufile, $ulog);
 }
Example #2
0
function run()
{
    global $user;
    global $layout;
    global $DB;
    global $website;
    $out = '';
    $item = new extension();
    switch ($_REQUEST['act']) {
        case 'extension_info':
            echo '<iframe src="' . NAVIGATE_URL . '/plugins/' . $_REQUEST['extension'] . '/' . $_REQUEST['extension'] . '.info.html' . '" scrolling="auto" frameborder="0"  width="100%" height="100%"></iframe>';
            core_terminate();
            break;
        case 'disable':
            $extension = new extension();
            $extension->load($_REQUEST['extension']);
            $extension->enabled = 0;
            $ok = $extension->save();
            echo json_encode($ok);
            core_terminate();
            break;
        case 'enable':
            $extension = new extension();
            $extension->load($_REQUEST['extension']);
            $extension->enabled = 1;
            $ok = $extension->save();
            echo json_encode($ok);
            core_terminate();
            break;
            // TODO: rework favorite extensions as user's favorite (not global)
            /*
            case 'favorite':
                $extension = new extension();
                $extension->load($_REQUEST['extension']);
                $extension->favorite = intval($_REQUEST['value']);
                $ok = $extension->save();
                echo json_encode($ok);
                core_terminate();
                break;
            */
        // TODO: rework favorite extensions as user's favorite (not global)
        /*
        case 'favorite':
            $extension = new extension();
            $extension->load($_REQUEST['extension']);
            $extension->favorite = intval($_REQUEST['value']);
            $ok = $extension->save();
            echo json_encode($ok);
            core_terminate();
            break;
        */
        case 'remove':
            try {
                $extension = new extension();
                $extension->load($_REQUEST['extension']);
                $status = $extension->delete();
                echo json_encode($status);
            } catch (Exception $e) {
                echo $e->getMessage();
            }
            core_terminate();
            break;
        case 'options':
            $extension = new extension();
            $extension->load($_REQUEST['extension']);
            $status = null;
            if (isset($_REQUEST['form-sent'])) {
                $extension->load_from_post();
                $status = $extension->save();
            }
            $out = extensions_options($extension, $status);
            echo $out;
            core_terminate();
            break;
        case 'dialog':
            $extension = new extension();
            $extension->load($_REQUEST['extension']);
            $out = extensions_dialog($extension, $_REQUEST['function'], $_REQUEST);
            echo $out;
            core_terminate();
            break;
        case 'process':
            $extension = trim($_REQUEST['extension']);
            call_user_func("nvweb_" . $extension . "_plugin", $_REQUEST);
            core_terminate();
            break;
        case 'run':
            $extension = trim($_REQUEST['extension']);
            $extensions_allowed = $user->permission("extensions.allowed");
            if (!empty($extensions_allowed) && !in_array($extension, $extensions_allowed)) {
                $out = t(610, "Sorry, you are not allowed to execute this function.");
            } else {
                if (file_exists(NAVIGATE_PATH . '/plugins/' . $extension . '/run.php')) {
                    include_once NAVIGATE_PATH . '/plugins/' . $extension . '/run.php';
                    if (function_exists($extension . '_run')) {
                        eval('$out = ' . $extension . '_run();');
                    }
                }
            }
            break;
        case 'install_from_hash':
            $url = base64_decode($_GET['hash']);
            if (!empty($url) && $user->permission("extensions.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 extensions dir
                    @mkdir(NAVIGATE_PATH . '/plugins/' . $query['code']);
                    $zip = new ZipArchive();
                    $zip_open_status = $zip->open($tmp_file);
                    if ($zip_open_status === TRUE) {
                        $zip->extractTo(NAVIGATE_PATH . '/plugins/' . $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 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 'extension_upload':
            if (isset($_FILES['extension-upload']) && $_FILES['extension-upload']['error'] == 0 && $user->permission("extensions.install") == "true") {
                // uncompress ZIP and copy it to the extensions dir
                $tmp = trim(substr($_FILES['extension-upload']['name'], 0, strpos($_FILES['extension-upload']['name'], '.')));
                $extension_name = filter_var($tmp, FILTER_SANITIZE_EMAIL);
                if ($tmp != $extension_name) {
                    $layout->navigate_notification(t(344, 'Security error'), true, true);
                } else {
                    @mkdir(NAVIGATE_PATH . '/plugins/' . $extension_name);
                    $zip = new ZipArchive();
                    if ($zip->open($_FILES['extension-upload']['tmp_name']) === TRUE) {
                        $zip->extractTo(NAVIGATE_PATH . '/plugins/' . $extension_name);
                        $zip->close();
                        $layout->navigate_notification(t(374, "Item installed successfully."), false);
                    } else {
                        $layout->navigate_notification(t(262, 'Error uploading file'), true, true);
                    }
                }
            }
        default:
            $list = extension::list_installed(null, false);
            $out = extensions_grid($list);
            break;
    }
    return $out;
}
Example #3
0
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;
}