Skip to content

Commit

Permalink
Add Sitemap and
Browse files Browse the repository at this point in the history
Meta description
WWBN#999
  • Loading branch information
daniel authored and daniel committed Sep 5, 2018
1 parent ea24769 commit 4a74152
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 16 deletions.
113 changes: 113 additions & 0 deletions objects/configurationGenerateSiteMap.json.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

function siteMap() {
global $global;
$date = date('Y-m-d\TH:i:s') . "+00:00";

$xml = '<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<!-- Main Page -->
<url>
<loc>'.$global['webSiteRootURL'].'</loc>
<lastmod>'.$date.'</lastmod>
<changefreq>always</changefreq>
<priority>1.00</priority>
</url>
<url>
<loc>'.$global['webSiteRootURL'].'help</loc>
<lastmod>'.$date.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.50</priority>
</url>
<url>
<loc>'.$global['webSiteRootURL'].'about</loc>
<lastmod>'.$date.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.50</priority>
</url>
<url>
<loc>'.$global['webSiteRootURL'].'contact</loc>
<lastmod>'.$date.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.50</priority>
</url>
<!-- Channels -->
<url>
<loc>'.$global['webSiteRootURL'].'channels</loc>
<lastmod>'.$date.'</lastmod>
<changefreq>daily</changefreq>
<priority>0.80</priority>
</url>
';
$users = User::getAllUsers(true);
foreach ($users as $value) {
$xml .= '
<url>
<loc>'.User::getChannelLink($value['id']).'</loc>
<lastmod>'.$date.'</lastmod>
<changefreq>daily</changefreq>
<priority>0.70</priority>
</url>
';
}
$xml .= '
<!-- Categories -->
';
$rows = Category::getAllCategories();
foreach ($rows as $value) {
$xml .= '
<url>
<loc>'.$global['webSiteRootURL'].'cat/'.$value['clean_name'].'</loc>
<lastmod>'.$date.'</lastmod>
<changefreq>weekly</changefreq>
<priority>0.80</priority>
</url>
';
}
$xml .= '<!-- Videos -->';
$rows = Video::getAllVideos("viewable");
foreach ($rows as $value) {
$xml .= '
<url>
<loc>'.Video::getLink($value['id'], $value['clean_title']).'</loc>
<lastmod>'.$date.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.80</priority>
</url>
';
}
$xml .= '</urlset> ';
return $xml;
}

//header("Content-type: text/xml");
header('Content-Type: application/json');
global $global, $config;
if (!isset($global['systemRootPath'])) {
require_once '../videos/configuration.php';
}
require_once $global['systemRootPath'] . 'objects/user.php';

$obj = new stdClass();
$obj->error = true;
$obj->msg = "";

if (!User::isAdmin()) {
$obj->msg = __("Permission denied");
die(json_encode($obj));
}
$sitemap = siteMap();

if(!file_put_contents($sitemapFile, $sitemap)){
$obj->msg = "We could not save the sitemap";
die(json_encode($obj));
}

$obj->error = false;
die(json_encode($obj));
2 changes: 1 addition & 1 deletion objects/configurationUpdate.json.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

$config->setHead($_POST['head']);
$config->setAdsense($_POST['adsense']);
$config->setMode($_POST['mode']);
$config->setMode('Youtube');

$config->setAutoplay($_POST['autoplay']);
$config->setTheme($_POST['theme']);
Expand Down
3 changes: 2 additions & 1 deletion objects/include_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@
if(class_exists("Plugin")){YouPHPTubePlugin::getStart();}
else{error_log("Class Plugin Not found: {$_SERVER['REQUEST_URI']}");}
$global['allowedExtension'] = array('gif', 'jpg', 'mp4', 'webm');
$advancedCustom = YouPHPTubePlugin::getObjectDataIfEnabled("CustomizeAdvanced");
$advancedCustom = YouPHPTubePlugin::getObjectDataIfEnabled("CustomizeAdvanced");
$sitemapFile = "{$global['systemRootPath']}sitemap.xml";
9 changes: 9 additions & 0 deletions sitemap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<!-- Main Page -->

</urlset>
42 changes: 28 additions & 14 deletions view/configurations.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,18 +293,6 @@
<input type="file" id="logoSmall" value="Choose a Small Logo" accept="image/*" style="display: none;" />
</div>

<div class="form-group">
<label class="col-md-4 control-label"><?php echo __("First Page Mode"); ?></label>
<div class="col-md-8 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-sitemap"></i></span>
<select class="form-control" id="mode" >
<option value="Youtube" <?php echo ($config->getMode() == "Youtube") ? "selected" : ""; ?>><?php echo __("Youtube"); ?></option>
</select>
</div>
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label"><?php echo __("Web site title"); ?></label>
<div class="col-md-8 inputGroupContainer">
Expand Down Expand Up @@ -398,7 +386,17 @@
<div class="form-group">
<div class="col-md-12">
<button class="btn btn-danger" id="clearCache"><i class="fa fa-trash"></i> <?php echo __("Clear Cache Directory"); ?></button>

<button class="btn btn-primary" id="generateSiteMap"><i class="fa fa-sitemap"></i> <?php echo __("Generate Sitemap"); ?></button>
<?php
if(!is_writable($sitemapFile)){
?>
<div class="alert alert-danger">
the sitemap file must be writable
<code>sudo chmod 777 <?php echo $sitemapFile; ?></code>
</div>
<?php
}
?>
</div>
</div>
<div class="form-group">
Expand Down Expand Up @@ -660,7 +658,24 @@ function readFile(input, c) {
modal.hidePleaseWait();
}
});
});

$('#generateSiteMap').on('click', function (ev) {
ev.preventDefault();
modal.showPleaseWait();
$.ajax({
url: '<?php echo $global['webSiteRootURL']; ?>objects/configurationGenerateSiteMap.json.php',
success: function (response) {
if (!response.error) {
swal("<?php echo __("Congratulations!"); ?>", "<?php echo __("File created!"); ?>", "success");
} else {
swal("<?php echo __("Sorry!"); ?>", "<?php echo __("File NOT created!"); ?>", "error");
}
modal.hidePleaseWait();
}
});
});

$('#logo-result-btn').on('click', function (ev) {
logoCrop.croppie('result', {
type: 'canvas',
Expand Down Expand Up @@ -754,7 +769,6 @@ function readFile(input, c) {
"authCanComment": $('#authCanComment').val(),
"head": $('#head').val(),
"adsense": $('#adsense').val(),
"mode": $('#mode').val(),
"disable_analytics": $('#disable_analytics').prop("checked"),
"disable_youtubeupload": $('#disable_youtubeupload').prop("checked"),
"allow_download": $("#allow_download").prop("checked"),
Expand Down

0 comments on commit 4a74152

Please sign in to comment.