function put_contents($file, $contents, $type = '') { if (!gpFiles::Save($file, $contents)) { return false; } //the gpEasy core does not need to be world writable @chmod($file, FS_CHMOD_FILE); return true; }
/** * Get the remote package * */ function GetRemote() { global $langmessage, $dataDir; includeFile('tool/RemoteGet.php'); // check values if (empty($this->type) || empty($this->id) || !is_numeric($this->id)) { $this->message($langmessage['OOPS'] . ' (Invalid Request)'); return false; } // allowed to remote install? switch ($this->type) { case 'plugin': if (!gp_remote_plugins) { $this->message($langmessage['OOPS'] . ' (Can\'t remote install plugins)'); return false; } break; case 'theme': if (!gp_remote_themes) { $this->message($langmessage['OOPS'] . ' (Can\'t remote install themes)'); return false; } break; default: $this->message($langmessage['OOPS'] . ' (Invalid Type)'); return false; } // able to remote install? if (!admin_tools::CanRemoteInstall()) { $this->message($langmessage['OOPS'] . ' (Can\'t remote install)'); return false; } // download $download_link = addon_browse_path; if ($this->type == 'theme') { $download_link .= '/Themes'; } else { $download_link .= '/Plugins'; } $download_link .= '?cmd=install&id=' . rawurlencode($this->id); // purchase order id if (!$this->order) { $this->order = $this->GetOrder($this->id); } if ($this->order) { $download_link .= '&order=' . rawurlencode($this->order); } // get package from remote $full_result = gpRemoteGet::Get($download_link); if ((int) $full_result['response']['code'] < 200 && (int) $full_result['response']['code'] >= 300) { $this->message($langmessage['download_failed'] . ' (1)'); return false; } // download failed and a message was sent if (isset($full_result['headers']['x-error'])) { $this->message(htmlspecialchars($full_result['headers']['x-error'])); $this->message(sprintf($langmessage['download_failed_xerror'], 'href="' . $this->DetailUrl($_POST['type'], $_POST['id']) . '" data-cmd="remote"')); return false; } $result = $full_result['body']; $md5 =& $full_result['headers']['x-md5']; //check md5 $package_md5 = md5($result); if ($package_md5 != $md5) { $this->message($langmessage['download_failed_md5'] . ' <br/> (Package Checksum ' . $package_md5 . ' != Expected Checksum ' . $md5 . ')'); return false; } //save contents $tempfile = $dataDir . \gp\tool\FileSystem::TempFile('/data/_temp/addon', '.zip'); if (!gpFiles::Save($tempfile, $result)) { $this->message($langmessage['download_failed'] . ' (Package not saved)'); return false; } $this->source = $this->TempFile(); $success = $this->ExtractArchive($tempfile); unlink($tempfile); return $success; }
/** * Regenerate the static content used to display the archive gadget * */ static function GenArchiveGadget() { global $addonPathData; //get list of posts and times $list = SimpleBlogCommon::AStrToArray('post_times'); if (!count($list)) { return; } //get year counts $archive = array(); foreach ($list as $post_id => $time) { $ym = date('Y-m', $time); //year&month $archive[$ym][] = $post_id; } ob_start(); $prev_year = false; echo '<ul>'; foreach ($archive as $ym => $posts) { $y = substr($ym, 0, 4); $m = substr($ym, -2); if ($y != $prev_year) { if ($prev_year !== false) { echo '</li>'; } echo '<li><div class="simple_blog_gadget_year">' . $y . '</div>'; $prev_year = $y; } $sum = count($posts); if (!$sum) { continue; } echo '<ul>'; echo '<li><a class="blog_gadget_link">'; $time = strtotime($ym . '-01'); echo strftime('%B', $time); echo ' (' . $sum . ')</a>'; echo '<ul class="simple_blog_category_posts nodisplay">'; foreach ($posts as $post_id) { $post_title = SimpleBlogCommon::AStrGet('titles', $post_id); echo '<li>'; echo SimpleBlogCommon::PostLink($post_id, $post_title); echo '</li>'; } echo '</ul>'; echo '</li>'; echo '</ul>'; } echo '</li></ul>'; $content = ob_get_clean(); $gadgetFile = $addonPathData . '/gadget_archive.php'; gpFiles::Save($gadgetFile, $content); }
/** * Convert a .less file to .css and include it in the page * @param mixed $less_files A strin or array of less filesThe absolute or relative path of the .less file * */ static function CacheLess($less_files) { global $dataDir; //generage the name of the css file from the modified times and content length of each imported less file $files_hash = common::ArrayHash($less_files); $list_file = $dataDir . '/data/_cache/less_' . $files_hash . '.list'; if (file_exists($list_file)) { $list = explode("\n", file_get_contents($list_file)); //pop the etag $etag = array_pop($list); if (!ctype_alnum($etag)) { $list[] = $etag; $etag = false; } // generate an etag if needed or if logged in if (!$etag || common::LoggedIn()) { $etag = common::FilesEtag($list); } $compiled_name = 'less_' . $files_hash . '_' . $etag . '.css'; $compiled_file = '/data/_cache/' . $compiled_name; if (file_exists($dataDir . $compiled_file)) { //msg('not using cache'); return $compiled_file; } } $less_files = (array) $less_files; $compiled = gpOutput::ParseLess($less_files, $files_hash); if (!$compiled) { return false; } // generate the file name $etag = common::FilesEtag($less_files); $compiled_name = 'less_' . $files_hash . '_' . $etag . '.css'; $compiled_file = '/data/_cache/' . $compiled_name; // save the cache // use the last line for the etag $less_files[] = $etag; $cache = implode("\n", $less_files); if (!gpFiles::Save($list_file, $cache)) { return false; } //save the css if (file_put_contents($dataDir . $compiled_file, $compiled)) { return $compiled_file; } return false; }
/** * Get addon data from gpEasy.com and display to user * */ function RemoteBrowse() { global $langmessage, $config, $dataDir, $gpversion; //search options if (isset($_GET['search_option'])) { $save = true; switch ($_GET['search_option']) { case 'version': unset($config['search_version']); break; case 'noversion': $config['search_version'] = false; break; default: $save = false; break; } if ($save) { admin_tools::SaveConfig(); } } //make a list of installed addon id's $this->installed_ids = array(); if (isset($config['addons']) && is_array($config['addons'])) { foreach ($config['addons'] as $addon_info) { if (isset($addon_info['id'])) { $this->installed_ids[] = $addon_info['id']; } } } includeFile('tool/RemoteGet.php'); $orderby = array(); $orderby['rating_score'] = $langmessage['Highest Rated']; $orderby['downloads'] = $langmessage['Most Downloaded']; $orderby['modified'] = $langmessage['Recently Updated']; $orderby['created'] = $langmessage['Newest']; $_GET += array('q' => ''); $this->searchPage = 0; if (isset($_REQUEST['page']) && ctype_digit($_REQUEST['page'])) { $this->searchPage = $_REQUEST['page']; } $this->searchQuery = 'cmd=remote'; //version specific search $search_version = false; if (!isset($config['search_version']) || $config['search_version']) { $this->searchQuery .= '&ug=' . rawurlencode($gpversion); $search_version = true; } if (!empty($_GET['q'])) { $this->searchQuery .= '&q=' . rawurlencode($_GET['q']); } if (isset($_GET['order']) && isset($orderby[$_GET['order']])) { $this->searchOrder = $_GET['order']; $this->searchQuery .= '&order=' . rawurlencode($_GET['order']); } else { reset($orderby); $this->searchOrder = key($orderby); } $slug = 'Special_Addon_Plugins'; if ($this->config_index == 'themes') { $slug = 'Special_Addon_Themes'; } $src = $GLOBALS['addonBrowsePath'] . '/' . $slug . '?' . $this->searchQuery . '&page=' . $this->searchPage; //check cache $cache_file = $dataDir . '/data/_remote/' . sha1($src) . '.txt'; $use_cache = false; if (file_exists($cache_file) && filemtime($cache_file) + 26100 > time()) { $result = file_get_contents($cache_file); $use_cache = true; } else { $result = gpRemoteGet::Get_Successful($src); } if (!$result) { echo '<p>' . $langmessage['Sorry, data not fetched'] . ' (f1)</p>'; return; } if (strpos($result, 'a:') !== 0) { echo '<p>' . $langmessage['Sorry, data not fetched'] . ' (f2)</p>'; return; } $data = unserialize($result); if (count($data) == 0) { echo '<p>' . $langmessage['Sorry, data not fetched'] . ' (f3)</p>'; return; } //save the cache if (!$use_cache) { gpFiles::Save($cache_file, $result); } $this->searchMax = $data['max']; if (isset($data['per_page']) && $data['per_page']) { $this->searchPerPage = $data['per_page']; } else { $this->searchPerPage = count($data['rows']); } $this->searchOffset = $this->searchPage * $this->searchPerPage; $this->FindForm(); echo '<h2 class="hmargin">'; echo common::Link($this->browser_path, $this->manage_label); echo ' <span>|</span> '; if (!empty($_GET['q'])) { echo common::Link($this->browser_path, $this->find_label, 'cmd=remote'); echo ' » '; echo htmlspecialchars($_GET['q']); } else { echo $this->find_label; } echo '</h2>'; echo '<div class="gp_search_options">'; $this->SearchNavLinks(); echo '<div class="search_order">'; foreach ($orderby as $key => $label) { if ($key === $this->searchOrder) { echo '<span>' . $label . '</span>'; } else { echo common::Link($this->browser_path, $label, $this->searchQuery . '&order=' . $key); } } echo '</div></div>'; echo '<table class="bordered full_width">'; echo '<tr><th></th><th>' . $langmessage['name'] . '</th><th>' . $langmessage['version'] . '</th><th>' . $langmessage['Statistics'] . '</th><th>' . $langmessage['description'] . '</th></tr>'; $i = 0; if (count($data['rows'])) { foreach ($data['rows'] as $row) { echo '<tr class="' . ($i % 2 ? 'even' : '') . '">'; echo '<td>'; $this->DetailLink($row, '<img src="' . $row['icon'] . '" height="100" width="100" alt=""/>', '', ' class="shot"'); echo '</td>'; echo '<td class="nowrap">'; echo '<b>' . $row['name'] . '</b>'; echo '<br/>'; $this->DetailLink($row); echo ' | '; $this->InstallLink($row); echo '</td><td>'; echo $row['version']; echo '</td><td class="nowrap">'; echo sprintf($langmessage['_downloads'], number_format($row['downloads'])); echo '<br/>'; $this->CurrentRating($row['rating_weighted']); echo '<br/>'; echo $row['rating_count'] . ' ratings'; echo '</td><td>'; echo $row['short_description']; //echo showArray($row); echo '</td></tr>'; $i++; } echo '</table>'; $this->SearchNavLinks(); } else { echo '</table>'; echo '<p>' . $langmessage['Sorry, nothing matched'] . '</p>'; } echo '<h3>Search Options</h3>'; echo '<ul>'; echo '<li>Limit results to addons that are compatible with your version of gpEasy (' . $gpversion . ') '; if ($search_version) { echo '<b>' . $langmessage['On'] . '</b> '; echo common::Link($this->browser_path, $langmessage['Off'], $this->searchQuery . '&search_option=noversion', ' name="gpajax"'); } else { echo common::Link($this->browser_path, $langmessage['On'], $this->searchQuery . '&search_option=version', ' name="gpajax"'); echo ' <b>' . $langmessage['Off'] . '</b>'; } echo '</li>'; echo '</ul>'; }
/** * Regenerate the static content used to display the gadget * */ function GenGadget() { global $langmessage; $posts = array(); $show_posts = $this->WhichPosts(0, $this->blogData['gadget_entries']); ob_start(); $label = gpOutput::SelectText('Blog'); if (!empty($label)) { echo '<h3>'; echo common::Link('Special_Blog', $label); echo '</h3>'; } foreach ($show_posts as $post_index) { //get $posts if (!isset($posts[$post_index])) { $posts = $this->GetPostFile($post_index, $post_file); } if (!isset($posts[$post_index])) { continue; } $post =& $posts[$post_index]; $header = '<b class="simple_blog_title">'; $label = str_replace('_', ' ', $post['title']); $header .= common::Link('Special_Blog', $label, 'id=' . $post_index); $header .= '</b>'; $this->BlogHead($header, $post_index, $post, true); $content = strip_tags($post['content']); if ($this->blogData['gadget_abbrev'] > 6 && strlen($content) > $this->blogData['gadget_abbrev']) { $cut = $this->blogData['gadget_abbrev']; //php4 strpos //$pos = strpos($content,' ',$cut-5); $temp = substr($content, $cut - 5); $pos = strpos($temp, ' ') + $cut - 5; if ($pos > 0 && $cut + 20 > $pos) { $cut = $pos; } $content = substr($content, 0, $cut) . ' ... '; $label = gpOutput::SelectText('Read More'); $content .= common::Link('Special_Blog', $label, 'id=' . $post_index); } echo '<p class="simple_blog_abbrev">'; echo $content; echo '</p>'; } if ($this->blogData['post_count'] > 3) { $label = gpOutput::SelectText('More Blog Entries'); echo common::Link('Special_Blog', $label); } $gadget = ob_get_clean(); $gadgetFile = $this->addonPathData . '/gadget.php'; gpFiles::Save($gadgetFile, $gadget); }
/** * Put the files in $file_list in the destination folder * If the second destination folder is set, use gpFiles methods * * @param array $file_list List of files * @param string $dest_rel The relative destination directory for $file_list * @param bool $gpfiles False to use $gp_filesystem for file replacement, True for gpFiles methods * @return bool */ function PutFiles($file_list, $dest_rel, $gpfiles = false) { global $gp_filesystem, $langmessage, $dataDir; $dest_fs = $gp_filesystem->get_base_dir() . $dest_rel; if ($gpfiles) { $dest = $dataDir . $dest_rel; } //create destination if (!$gp_filesystem->mkdir($dest_fs)) { message($langmessage['revert_failed'] . ' Directory not created (0)'); return false; } foreach ($file_list as $file_info) { $path =& $file_info['filename']; $flag = (int) $file_info['typeflag']; $full_fs = $dest_fs . $file_info['relative_path']; $full = false; if ($gpfiles) { $full = $dest . $file_info['relative_path']; } //create directories if ($flag === 5) { if ($full) { if (!gpFiles::CheckDir($full, false)) { message($langmessage['revert_failed'] . ' Directory not created (1)'); return false; } continue; } if (!$gp_filesystem->mkdir($full_fs)) { message($langmessage['revert_failed'] . ' Directory not created (2)'); return false; } continue; } //create files if ($flag === 0) { $contents = $this->GetImportContents($path); if ($full) { if (!gpFiles::Save($full, $contents)) { message($langmessage['revert_failed'] . ' File not created (1)'); return false; } } if (!$gp_filesystem->put_contents($full_fs, $contents)) { message($langmessage['revert_failed'] . ' File not created (2)'); return false; } continue; } //symbolic link if ($flag === 2) { $target = $this->FixLink($file_info['link']); /* * This is too restrictive * Can't even check the new folders being created in case the target hasn't been prepared yet * if( !file_exists($target) ){ message($langmessage['revert_failed'].' Symlink target doesn\'t exist.'); return false; } */ if (!symlink($target, $full)) { message($langmessage['revert_failed'] . ' Symlink not created (1)'); return false; } } } return true; }
function DownloadSource(&$package) { global $langmessage, $addonBrowsePath; /* for testing * $download = 'http://test.gpeasy.com/gpEasy_test.zip'; * $download = 'http://gpeasy.loc/rocky/x_gpEasy_test.zip'; */ $download = $addonBrowsePath . '/Special_gpEasy?cmd=download&version=' . urlencode($package['version']) . '&file=' . urlencode($package['zip']); echo '<li>Downloading version ' . $package['version'] . ' from gpEasy.com.</li>'; $contents = gpRemoteGet::Get_Successful($download); if (!$contents || empty($contents)) { echo '<li>' . $langmessage['download_failed'] . ' (1)</li>'; return false; } echo '<li>' . $langmessage['package_downloaded'] . '</li>'; $md5 = md5($contents); if ($md5 != $package['md5']) { echo '<li>' . $langmessage['download_failed_md5']; echo '<br/>Downloaded Checksum (' . $md5 . ') != Expected Checksum (' . $package['md5'] . ')'; echo '</li>'; return false; } echo '<li>' . $langmessage['download_verified'] . '</li>'; //save contents $tempfile = $this->tempfile(); if (!gpFiles::Save($tempfile, $contents)) { message($langmessage['download_failed'] . ' (2)'); return false; } $package['file'] = $tempfile; return true; }
/** * Check recursively to see if a directory exists, if it doesn't attempt to create it * * @param string $dir The directory path * @param bool $index Whether or not to add an index.hmtl file in the directory * @return bool True on success */ function CheckDir($dir, $index = true) { global $config, $checkFileIndex; if (!file_exists($dir)) { $parent = dirname($dir); gpFiles::CheckDir($parent, $index); //ftp mkdir if (isset($config['useftp'])) { if (!gpFiles::FTP_CheckDir($dir)) { return false; } } else { if (!@mkdir($dir, gp_chmod_dir)) { return false; } @chmod($dir, gp_chmod_dir); //some systems need more than just the 0755 in the mkdir() function } } //make sure there's an index.html file if ($index && $checkFileIndex) { $indexFile = $dir . '/index.html'; if (!file_exists($indexFile)) { gpFiles::Save($indexFile, '<html></html>', false); } } return true; }
function CacheCSS($file) { global $dataDir; $cache_info = array(); $cache_info['min'] = md5($file) . '.css'; $cache_file = $dataDir . '/data/_cache/' . $cache_info['min']; //echo "\n cache file: ".$cache_file; //get all the cached files $temp = new gp_combine_css($file); //print_r($temp); gpFiles::Save($cache_file, $temp->content); $full_path = $dataDir . $file; $cache_info['mod'] = filemtime($full_path); $cache_info['len'] = filesize($full_path); if (is_array($temp->files) && count($temp->files) > 0) { $cache_info['import'] = $temp->files; } $this->css_data[$file] = $cache_info; $this->css_data_changed = true; return $cache_info; }
/** * Save the comment data for a blog post * */ function SaveCommentData($post_index, $data) { global $langmessage; // check directory $dir = $this->addonPathData . '/comments'; if (!gpFiles::CheckDir($dir)) { return false; } $commentDataFile = $dir . '/' . $post_index . '.txt'; $dataTxt = serialize($data); if (!gpFiles::Save($commentDataFile, $dataTxt)) { return false; } // clean pre 1.7.4 files $commentDataFile = $this->addonPathData . '/comments_data_' . $post_index . '.txt'; if (file_exists($commentDataFile)) { unlink($commentDataFile); } SimpleBlogCommon::AStrValue('comment_counts', $post_index, count($data)); $this->SaveIndex(); //clear comments cache $cache_file = $this->addonPathData . '/comments/cache.txt'; if (file_exists($cache_file)) { unlink($cache_file); } return true; }
/** * Save the comment data for a blog post * */ public static function SaveCommentData($post_index, $data) { global $langmessage; // check directory $dir = self::$data_dir . '/comments'; if (!gpFiles::CheckDir($dir)) { return false; } $commentDataFile = $dir . '/' . $post_index . '.txt'; $dataTxt = serialize($data); if (!gpFiles::Save($commentDataFile, $dataTxt)) { return false; } // clean pre 1.7.4 files $commentDataFile = self::$data_dir . '/comments_data_' . $post_index . '.txt'; if (file_exists($commentDataFile)) { unlink($commentDataFile); } SimpleBlogCommon::AStrSet('comment_counts', $post_index, count($data)); SimpleBlogCommon::SaveIndex(); SimpleBlogCommon::ClearCommentCache(); return true; }
/** * Revert the file data to a previous revision * */ public function UseRevision() { global $langmessage; $time = $_REQUEST['time']; $full_path = $this->BackupFile($time); if (is_null($full_path)) { return false; } if (strpos($full_path, '.gze') !== false) { ob_start(); readgzfile($full_path); $contents = ob_get_clean(); } else { $contents = file_get_contents($full_path); } $this->SaveBackup(); if (!gpFiles::Save($this->draft_file, $contents)) { //restore to the draft file msg($langmessage['OOPS'] . ' (Draft not saved)'); return false; } $this->draft_exists = true; $this->GetFile(); $this->SaveThis(false); //save again to update the mod time and username msg($langmessage['SAVED']); }
/** * Write Archive * */ function ExtractArchive($dir, $archive_path) { global $langmessage; // Unzip uses a lot of memory, but not this much hopefully @ini_set('memory_limit', '256M'); includeFile('thirdparty/pclzip-2-8-2/pclzip.lib.php'); $archive = new PclZip($archive_path); $archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING); if (!gpFiles::CheckDir($dir)) { $this->message(sprintf($langmessage['COULD_NOT_SAVE'], $folder)); return false; } //get archive root $archive_root = false; foreach ($archive_files as $file) { if (strpos($file['filename'], '/Addon.ini') !== false) { $root = dirname($file['filename']); if (!$archive_root || strlen($root) < strlen($archive_root)) { $archive_root = $root; } } } $archive_root_len = strlen($archive_root); foreach ($archive_files as $file_info) { $filename = $file_info['filename']; if ($archive_root) { if (strpos($filename, $archive_root) !== 0) { continue; } $filename = substr($filename, $archive_root_len); } $filename = '/' . trim($filename, '/'); $full_path = $dir . '/' . $filename; if ($file_info['folder']) { $folder = $full_path; } else { $folder = dirname($full_path); } if (!gpFiles::CheckDir($folder)) { $this->message(sprintf($langmessage['COULD_NOT_SAVE'], $folder)); return false; } if ($file_info['folder']) { continue; } if (!gpFiles::Save($full_path, $file_info['content'])) { $this->message(sprintf($langmessage['COULD_NOT_SAVE'], $full_path)); return false; } } return true; }
function GetRecent() { if (!file_exists($this->dir)) { return false; } $new_entries = false; $files = scandir($this->dir); foreach ($files as $file) { if ($file == '.' || $file == '..') { continue; } list($post_id, $ext) = explode('.', $file, 2); if (!is_numeric($post_id)) { continue; } //should already be part of the cache $full_path = $this->dir . '/' . $file; $mod_time = filemtime($full_path); if ($mod_time < $this->cache_mod) { continue; } $data = SimpleBlogCommon::FileData($full_path); foreach ($data as $comment) { if ($comment['time'] < $this->cache_mod) { continue; } $unique = $post_id . '.' . $comment['time']; $comment['post_id'] = $post_id; $this->cache[$unique] = $comment; $new_entries = true; } } if ($new_entries) { uasort($this->cache, array('SimpleBlogComments', 'Sort')); $dataTxt = serialize($this->cache); gpFiles::Save($this->cache_file, $dataTxt); } }
function CreateIndex($destination, $unique) { $path = $destination . '/index.php'; $indexA = array(); $indexA[] = '<' . '?' . 'php'; if (isset($this->siteData['service_provider_id'])) { $indexA[] = 'define(\'service_provider_id\',\'' . (int) $this->siteData['service_provider_id'] . '\');'; } if (isset($this->siteData['service_provider_name'])) { $indexA[] = 'define(\'service_provider_name\',\'' . addslashes($this->siteData['service_provider_name']) . '\');'; } $indexA[] = 'define(\'multi_site_unique\',\'' . $unique . '\');'; $indexA[] = 'require_once(\'include/main.php\');'; $index = implode("\n", $indexA); if (!gpFiles::Save($path, $index)) { return false; } @chmod($path, 0644); //to prevent 500 Internal Server Errors on some servers return true; }
/** * Generate a file with all of the combined content * */ static function GenerateFile($files, $type) { global $dataDir; //get etag $modified = $content_length = 0; $full_paths = array(); foreach ($files as $file) { $full_path = gp_combine::CheckFile($file); if ($full_path === false) { continue; } gp_combine::FileStat_Static($full_path, $modified, $content_length); $full_paths[$file] = $full_path; } //check css imports if ($type == 'css') { $had_imported = false; $import_data = array(); $imported_file = $dataDir . '/data/_cache/import_info.php'; if (file_exists($imported_file)) { include_once $imported_file; } foreach ($full_paths as $file => $full_path) { if (!isset($import_data[$full_path])) { continue; } $had_imported = true; foreach ($import_data[$full_path] as $imported_full) { gp_combine::FileStat_Static($imported_full, $modified, $content_length); } unset($import_data[$full_path]); } } //check to see if file exists $etag = common::GenEtag(json_encode($files), $modified, $content_length); $cache_relative = '/data/_cache/combined_' . $etag . '.' . $type; $cache_file = $dataDir . $cache_relative; if (file_exists($cache_file)) { // change modified time to extend cache if (time() - filemtime($cache_file) > 604800) { touch($cache_file); } return $cache_relative; } //create file if ($type == 'js') { ob_start(); common::jsStart(); foreach ($full_paths as $full_path) { readfile($full_path); echo ";\n"; } $combined_content = ob_get_clean(); } else { $imports = $combined_content = ''; $new_imported = array(); foreach ($full_paths as $file => $full_path) { $temp = new gp_combine_css($file); $combined_content .= "\n/* " . $file . " */\n"; $combined_content .= $temp->content; $imports .= $temp->imports; if (count($temp->imported)) { $new_imported[$full_path] = $temp->imported; } } $combined_content = $imports . $combined_content; //save imported data if (count($new_imported) || $had_imported) { if (count($new_imported)) { $import_data = $new_imported + $import_data; } gpFiles::SaveData($imported_file, 'import_data', $import_data); } } if (!gpFiles::Save($cache_file, $combined_content)) { return false; } includeFile('admin/admin_tools.php'); admin_tools::CleanCache(); return $cache_relative; }
/** * Revert the file data to a previous revision * */ function UseRevision() { global $langmessage, $page; $time = $_REQUEST['time']; $full_path = $this->BackupFile($time); if (!$full_path) { return false; } if (strpos($full_path, '.gze') !== false) { ob_start(); readgzfile($full_path); $contents = ob_get_clean(); } else { $contents = file_get_contents($full_path); } $this->SaveBackup(); gpFiles::Save($this->file, $contents); $this->GetFile(); $this->ResetFileTypes(false); message($langmessage['SAVED']); }
/** * Save array to a $file location * * @param string $file The location of the file to be saved * @param string $varname The name of the variable being saved * @param array $array The value of $varname to be saved * @param array $meta meta data to be saved along with $array * */ public static function SaveData($file, $varname, $array, $meta = array()) { global $dataDir; if (strpos($file, $dataDir) !== 0) { $file = $dataDir . '/data/' . ltrim($file, '/') . '.php'; } if (gp_data_type === '.json') { $file = substr($file, 0, -4) . '.gpjson'; $json = self::FileStart_Json($file); $json[$varname] = $array; $json['meta_data'] = $meta; $content = json_encode($json); } else { $content = gpFiles::FileStart($file); $content .= gpFiles::ArrayToPHP($varname, $array); $content .= "\n\n"; $content .= gpFiles::ArrayToPHP('meta_data', $meta); } return gpFiles::Save($file, $content); }
/** * Download the source code from gpeasy * */ function DownloadSource() { global $langmessage; $this->msg('Downloading version ' . $this->core_package['version'] . ' from gpEasy.com.'); /* for testing * $download = 'http://test.gpeasy.com/gpEasy_test.zip'; * $download = 'http://gpeasy.loc/x_gpEasy.zip'; */ $download = addon_browse_path . '/Special_gpEasy?cmd=download'; $contents = gpRemoteGet::Get_Successful($download); if (!$contents || empty($contents)) { $this->msg($langmessage['download_failed'] . '(1)'); return false; } $this->msg($langmessage['package_downloaded']); $md5 = md5($contents); if ($md5 != $this->core_package['md5']) { $this->msg($langmessage['download_failed_md5'] . '<br/>Downloaded Checksum (' . $md5 . ') != Expected Checksum (' . $this->core_package['md5'] . ')'); return false; } $this->msg($langmessage['download_verified']); //save contents $tempfile = $this->tempfile(); if (!gpFiles::Save($tempfile, $contents)) { $this->msg($langmessage['download_failed'] . ' (2)'); return false; } $this->core_package['file'] = $tempfile; return true; }
/** * Get addon data from gpEasy.com and display to user * */ function RemoteBrowse() { global $langmessage, $config, $dataDir; //search options if (isset($_GET['search_option'])) { $save = true; switch ($_GET['search_option']) { case 'version': unset($config['search_version']); break; case 'noversion': $config['search_version'] = false; break; default: $save = false; break; } if ($save) { admin_tools::SaveConfig(); } } //make a list of installed addon id's $this->installed_ids = array(); if (isset($config['addons']) && is_array($config['addons'])) { foreach ($config['addons'] as $addon_info) { if (isset($addon_info['id'])) { $this->installed_ids[] = $addon_info['id']; } } } includeFile('tool/RemoteGet.php'); //search settings $this->searchUrl = $this->path_remote; $this->searchOrderOptions['rating_score'] = $langmessage['Highest Rated']; $this->searchOrderOptions['downloads'] = $langmessage['Most Downloaded']; $this->searchOrderOptions['modified'] = $langmessage['Recently Updated']; $this->searchOrderOptions['created'] = $langmessage['Newest']; $_GET += array('q' => ''); if (isset($_REQUEST['page']) && ctype_digit($_REQUEST['page'])) { $this->searchPage = $_REQUEST['page']; } //version specific search $search_version = false; if (!isset($config['search_version']) || $config['search_version']) { $this->searchQuery .= '&ug=' . rawurlencode(gpversion); $search_version = true; } if (!empty($_GET['q'])) { $this->searchQuery .= '&q=' . rawurlencode($_GET['q']); } $this->SearchOrder(); $slug = 'Plugins'; if ($this->config_index == 'themes') { $slug = 'Themes'; } $src = addon_browse_path . '/' . $slug . '?cmd=remote&format=json&' . $this->searchQuery . '&page=' . $this->searchPage; // format=json added 4.6b3 //check cache $cache_file = $dataDir . '/data/_remote/' . sha1($src) . '.txt'; $use_cache = false; if (file_exists($cache_file) && filemtime($cache_file) + 26100 > time()) { $result = file_get_contents($cache_file); $use_cache = true; } else { $result = gpRemoteGet::Get_Successful($src); } //no response if (!$result) { if ($use_cache) { unlink($cache_file); } echo '<p>' . gpRemoteGet::Debug('Sorry, data not fetched') . '</p>'; return; } //serialized or json (serialized data may be cached) if (strpos($result, 'a:') === 0) { $data = unserialize($result); } elseif (strpos($result, '{') === 0) { $data = json_decode($result, true); } else { if ($use_cache) { unlink($cache_file); } $debug = array(); $debug['Two'] = substr($result, 0, 2); $debug['Twotr'] = substr(trim($result), 0, 2); echo '<p>' . gpRemoteGet::Debug('Sorry, data not fetched', $debug) . '</p>'; return; } //not unserialized? if (!is_array($data) || count($data) == 0) { if ($use_cache) { unlink($cache_file); } echo '<p>' . $langmessage['Sorry, data not fetched'] . ' (F3)</p>'; return; } //save the cache if (!$use_cache) { gpFiles::Save($cache_file, $result); } $this->searchMax = $data['max']; if (isset($data['per_page']) && $data['per_page']) { $this->searchPerPage = $data['per_page']; } else { $this->searchPerPage = count($data['rows']); } $this->ShowHeader(); $this->SearchOptions(); echo '<table class="bordered full_width">'; echo '<tr><th></th><th>' . $langmessage['name'] . '</th><th>' . $langmessage['version'] . '</th><th>' . $langmessage['Statistics'] . '</th><th>' . $langmessage['description'] . '</th></tr>'; $i = 0; if (count($data['rows'])) { foreach ($data['rows'] as $row) { echo '<tr class="' . ($i % 2 ? 'even' : '') . '">'; echo '<td>'; echo $this->DetailLink($row['type'], $row['id'], '<img src="' . $row['icon'] . '" height="100" width="100" alt=""/>', '', ' class="shot"'); echo '</td>'; echo '<td class="nowrap">'; echo '<b>' . $row['name'] . '</b>'; echo '<br/>'; echo $this->DetailLink($row['type'], $row['id']); echo ' | '; $this->InstallLink($row); echo '</td><td>'; echo $row['version']; echo '</td><td class="nowrap">'; echo sprintf($langmessage['_downloads'], number_format($row['downloads'])); echo '<br/>'; $this->CurrentRating($row['rating_weighted']); echo '<br/>'; echo $row['rating_count'] . ' ratings'; echo '</td><td>'; echo $row['short_description']; echo '</td></tr>'; $i++; } echo '</table>'; $this->SearchNavLinks(); } else { echo '</table>'; echo '<p>' . $langmessage['Sorry, nothing matched'] . '</p>'; } echo '<h3>Search Options</h3>'; echo '<ul>'; echo '<li>Limit results to addons that are compatible with your version of gpEasy (' . gpversion . ') '; if ($search_version) { echo '<b>' . $langmessage['On'] . '</b> '; echo common::Link($this->searchUrl, $langmessage['Off'], $this->searchQuery . '&search_option=noversion', ' data-cmd="gpajax"'); } else { echo common::Link($this->searchUrl, $langmessage['On'], $this->searchQuery . '&search_option=version', ' data-cmd="gpajax"'); echo ' <b>' . $langmessage['Off'] . '</b>'; } echo '</li>'; echo '</ul>'; }
/** * Save the comment data * */ function SaveCommentData() { global $langmessage; $dataTxt = serialize($this->comment_data); if (!gpFiles::Save($this->comment_data_file, $dataTxt)) { return false; } return true; }
/** * Perform a page copy * */ function CopyPage() { global $gp_index, $gp_titles, $page, $langmessage; //existing page info $from_title = $_POST['from_title']; if (!isset($gp_index[$from_title])) { message($langmessage['OOPS_TITLE']); return false; } $from_index = $gp_index[$from_title]; $info = $gp_titles[$from_index]; //check the new title $title = $_POST['title']; $title = admin_tools::CheckPostedNewPage($title, $message); if ($title === false) { message($message); return false; } //get the existing content $from_file = gpFiles::PageFile($from_title); $contents = file_get_contents($from_file); //add to $gp_index first! $index = common::NewFileIndex(); $gp_index[$title] = $index; $file = gpFiles::PageFile($title); if (!gpFiles::Save($file, $contents)) { message($langmessage['OOPS'] . ' (File not saved)'); return false; } //add to gp_titles $new_titles = array(); $new_titles[$index]['label'] = admin_tools::PostedLabel($_POST['title']); $new_titles[$index]['type'] = $info['type']; $gp_titles += $new_titles; if (!admin_tools::SavePagesPHP()) { message($langmessage['OOPS'] . ' (CP2)'); return false; } message($langmessage['SAVED']); if (isset($_REQUEST['redir'])) { $url = common::AbsoluteUrl($title, '', true, false); $page->ajaxReplace[] = array('eval', '', 'window.setTimeout(function(){window.location="' . $url . '"},15000);'); message(sprintf($langmessage['will_redirect'], common::Link_Page($title))); } return $index; }
/** * Save array to a $file location * * @param string $file The location of the file to be saved * @param string $varname The name of the variable being saved * @param array $array The value of $varname to be saved * @param array $meta meta data to be saved along with $array * */ public static function SaveData($file, $varname, $array, $meta = array()) { $file = self::FilePath($file); if (gp_data_type === '.json') { $json = self::FileStart_Json($file); $json[$varname] = $array; $json['meta_data'] = $meta; $content = json_encode($json); } else { $content = gpFiles::FileStart($file); $content .= gpFiles::ArrayToPHP($varname, $array); $content .= "\n\n"; $content .= gpFiles::ArrayToPHP('meta_data', $meta); } return gpFiles::Save($file, $content); }
/** * Copy a layout * */ function CopyLayout() { global $gpLayouts, $langmessage, $config, $page, $dataDir; $copy_id =& $_REQUEST['layout']; if (empty($copy_id) || !isset($gpLayouts[$copy_id])) { message($langmessage['OOPS'] . '(Invalid Request)'); return; } if (empty($_POST['label'])) { message($langmessage['OOPS'] . '(Empty Label)'); return; } $newLayout = $gpLayouts[$copy_id]; $newLayout['color'] = self::GetRandColor(); $newLayout['label'] = htmlspecialchars($_POST['label']); //get new unique layout id do { $layout_id = rand(1000, 9999); } while (isset($gpLayouts[$layout_id])); $gpLayoutsBefore = $gpLayouts; $gpLayouts[$layout_id] = $newLayout; if (!gpFiles::ArrayInsert($copy_id, $layout_id, $newLayout, $gpLayouts, 1)) { message($langmessage['OOPS'] . '(Not Inserted)'); return; } //copy any css $css = $this->layoutCSS($copy_id); if (!empty($css)) { $path = $dataDir . '/data/_layouts/' . $layout_id . '/custom.css'; if (!gpFiles::Save($path, $css)) { message($langmessage['OOPS'] . ' (CSS not saved)'); return false; } } if (admin_tools::SavePagesPHP()) { message($langmessage['SAVED']); } else { $gpLayouts = $gpLayoutsBefore; message($langmessage['OOPS'] . '(Not Saved)'); } }
/** * Perform a page copy * */ function CopyPage() { global $gp_index, $gp_titles, $page, $langmessage; $this->CacheSettings(); //existing page info $from_title = $_POST['from_title']; if (!isset($gp_index[$from_title])) { msg($langmessage['OOPS_TITLE']); return false; } $from_index = $gp_index[$from_title]; $info = $gp_titles[$from_index]; //check the new title $title = $_POST['title']; $title = admin_tools::CheckPostedNewPage($title, $message); if ($title === false) { msg($message); return false; } //get the existing content $from_file = gpFiles::PageFile($from_title); $contents = file_get_contents($from_file); //add to $gp_index first! $index = common::NewFileIndex(); $gp_index[$title] = $index; $file = gpFiles::PageFile($title); if (!gpFiles::Save($file, $contents)) { msg($langmessage['OOPS'] . ' (File not saved)'); return false; } //add to gp_titles $new_titles = array(); $new_titles[$index]['label'] = admin_tools::PostedLabel($_POST['title']); $new_titles[$index]['type'] = $info['type']; $gp_titles += $new_titles; //add to menu $insert = array(); $insert[$index] = array(); if (!$this->SaveNew($insert)) { $this->RestoreSettings(); return false; } $this->HiddenSaved($index); return true; }