1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 12:48:24 +01:00

Issue #3291 gSitemap table changes. Generic handling of link updates via e_gsitemap.php

This commit is contained in:
Cameron 2020-12-23 15:03:31 -08:00
parent c43da4d7aa
commit 450e392741
5 changed files with 132 additions and 226 deletions

View File

@ -4829,12 +4829,31 @@ class e_admin_controller_ui extends e_admin_controller
$pid = $this->getPrimaryName();
$_posted[$pid] = $id; // add in the primary ID field.
$table = $this->getTableName();
$pname = $this->getPluginName();
if($pname === 'core') // Handler 'core' plugin value.
{
$convert = array(
'news_category' => 'news',
'news' => 'news',
'page' => 'page',
'page_chapters' => 'page',
'user' => 'user'
);
if(!empty($convert[$table]))
{
$pname = $convert[$table];
}
}
$eventData = array( // use $_posted as it may include unsaved data.
'newData' => $_posted,
'oldData' => $old_data,
'id' => $id,
'table' => $this->getTableName(),
'plugin' => $this->getPluginName(),
'table' => $table,
'plugin' => $pname,
);
$this->_log('Triggering Event: ' . $triggerName);

View File

@ -133,6 +133,10 @@ class gsitemap_ui extends e_admin_ui
$this->fields['gsitemap_freq']['writeParms']['optArray'] = $this->freqList;
if(!empty($_POST['import_links']))
{
$this->importLink();
}
}
@ -187,6 +191,9 @@ class gsitemap_ui extends e_admin_ui
public function importPage()
{
global $PLUGINS_DIRECTORY;
$ns = e107::getRender();
@ -257,6 +264,7 @@ class gsitemap_ui extends e_admin_ui
{
if(!in_array($row['name'], $existing))
{
$row['plugin'] = $plug;
$importArray[] = $row;
}
}
@ -290,7 +298,8 @@ class gsitemap_ui extends e_admin_ui
$id = 'gs-'.$k;
$text .= "
<tr>
<td class='center'><input id='".$id."' type='checkbox' name='importid[]' value='".$ia['name']."^".$ia['url']."^".$ia['type']."^".$ia['table']."^".$ia['id']."' /></td>
<td class='center'><input id='".$id."' type='checkbox' name='importid[]'
value='".$ia['name']."^".$ia['url']."^".$ia['type']."^".$ia['plugin']."^".$ia['table']."^".$ia['id']."' /></td>
<td><label for='".$id."'>".$ia['type']."</label></td>
<td>".$ia['name']."</td>
<td><span class='smalltext'>".str_replace(SITEURL,"",$ia['url'])."</span></td>
@ -501,6 +510,50 @@ $text = "
*/
function importLink()
{
$sql = e107::getDb();
$tp = e107::getParser();
$log = e107::getLog();
foreach ($_POST['importid'] as $import)
{
list($name, $url, $type, $plugin, $table, $id) = explode("^", $import);
$insert = array(
'gsitemap_id' => 0,
'gsitemap_name' => $tp->toDB($name),
'gsitemap_url' => $tp->toDB($url),
'gsitemap_plugin' => $tp->toDB($plugin),
'gsitemap_table' => $tp->toDB($table),
'gsitemap_table_id' => (int) $id,
'gsitemap_lastmod' => time(),
'gsitemap_freq' => $_POST['import_freq'],
'gsitemap_priority' => $_POST['import_priority'],
'gsitemap_cat' => $type,
'gsitemap_order' => '0',
'gsitemap_img' => '',
'gsitemap_active' => '0',
);
if ($sql->insert("gsitemap", $insert))
{
e107::getMessage()->addSuccess(LAN_CREATED);
$log->add('GSMAP_01', $gsitemap->message);
}
else
{
e107::getMessage()->addError(LAN_CREATED_FAILED);
}
// $sql->insert("gsitemap", "0, '$name', '$url', '".time()."', '".$_POST['import_freq']."', '".$_POST['import_priority']."', '$type', '0', '', '0' ");
}
// $this->message = count($_POST['importid'])." link(s) imported.";
$log->add('GSMAP_01', $gsitemap->message);
}
}
@ -619,6 +672,7 @@ class gsitemap
"never" => LAN_NEVER
);
if(isset($_POST['edit']))
{
$this->editSme();
@ -634,10 +688,7 @@ class gsitemap
$this->addLink();
}
if(isset($_POST['import_links']))
{
$this->importLink();
}
if($this->message)
@ -659,7 +710,7 @@ class gsitemap
}
else if(e_QUERY == "import")
{
$this->importSme();
// $this->importSme();
}
else if(e_QUERY == "instructions")
{
@ -939,198 +990,6 @@ class gsitemap
}
}
// Import site links
function importSme()
{
global $PLUGINS_DIRECTORY;
$ns = e107::getRender();
$sql = e107::getDb();
//$sql2 = e107::getDb('sql2'); not used?
$frm = e107::getForm();
$mes = e107::getMessage();
$existing = array();
$sql->select("gsitemap");
while($row = $sql->fetch())
{
$existing[] = $row['gsitemap_name'];
}
$importArray = array();
/* sitelinks ... */
$sql->select("links", "*", "ORDER BY link_order ASC", "no-where");
$nfArray = $sql->db_getList();
foreach($nfArray as $row)
{
if(!in_array($row['link_name'], $existing))
{
$importArray[] = array(
'table' => 'links',
'id' => $row['link_id'],
'name' => $row['link_name'],
'url' => $row['link_url'],
'type' => GSLAN_1);
}
}
/* custom pages ... */
$query = "SELECT p.page_id, p.page_title, p.page_sef, p.page_chapter, ch.chapter_sef as chapter_sef, b.chapter_sef as book_sef FROM #page as p
LEFT JOIN #page_chapters as ch ON p.page_chapter = ch.chapter_id
LEFT JOIN #page_chapters as b ON ch.chapter_parent = b.chapter_id
WHERE page_title !='' ORDER BY page_datestamp ASC";
$data = $sql->retrieve($query,true);
foreach($data as $row)
{
if(!in_array($row['page_title'], $existing))
{
$route = ($row['page_chapter'] == 0) ? "page/view/other" : "page/view/index";
$importArray[] = array(
'table' => 'page',
'id' => $row['page_id'],
'name' => $row['page_title'],
'url' => e107::getUrl()->create($route, $row, array('full'=>1, 'allow' => 'page_sef,page_title,page_id, chapter_sef, book_sef')),
'type' => "Page"
);
}
}
/* Plugins.. - currently: forums ... */
$addons = e107::getAddonConfig('e_gsitemap', null, 'import');
foreach($addons as $plug => $config)
{
foreach($config as $row)
{
if(!in_array($row['name'], $existing))
{
$importArray[] = $row;
}
}
}
$editArray = $_POST;
$text = "
<form action='".e_SELF."' id='form' method='post'>
<table class='table adminlist table-striped table-condensed'>
<colgroup>
<col class='center' style='width:5%;' />
<col style='width:15%' />
<col style='width:40%' />
<col style='width:40%' />
</colgroup>
<thead>
<tr>
<th class='center'>".GSLAN_2."</th>
<th>".LAN_TYPE."</th>
<th>".LAN_NAME."</th>
<th>".LAN_URL."</th>
</tr>
</thead>
<tbody>
";
foreach($importArray as $k=>$ia)
{
$id = 'gs-'.$k;
$text .= "
<tr>
<td class='center'><input id='".$id."' type='checkbox' name='importid[]' value='".$ia['name']."^".$ia['url']."^".$ia['type']."^".$ia['table']."^".$ia['id']."' /></td>
<td><label for='".$id."'>".$ia['type']."</label></td>
<td>".$ia['name']."</td>
<td><span class='smalltext'>".str_replace(SITEURL,"",$ia['url'])."</span></td>
</tr>
";
}
$text .= "
<tr>
<td colspan='4' class='center'>
<div class='buttons-bar'> ".GSLAN_8." &nbsp; ".GSLAN_9." :&nbsp;<select class='tbox' name='import_priority' >\n";
for ($i=0.1; $i<1.0; $i=$i+0.1)
{
$sel = (vartrue($editArray['gsitemap_priority']) == number_format($i,1))? "selected='selected'" : "";
$text .= "<option value='".number_format($i,1)."' $sel>".number_format($i,1)."</option>\n";
}
$text.="</select>&nbsp;&nbsp;&nbsp;".GSLAN_10."
<select class='tbox' name='import_freq' >\n";
foreach($this->freq_list as $k=>$fq)
{
$sel = (vartrue($editArray['gsitemap_freq']) == $k)? "selected='selected'" : "";
$text .= "<option value='{$k}' {$sel}>{$fq}</option>\n";
}
$text .= "</select> <br /><br />
</div>
</td>
</tr>
</tbody>
</table>
<div class='buttons-bar center'>
".
$frm->admin_button('import_links',GSLAN_18)."
</div>
</form>
";
$ns->tablerender(GSLAN_7, $mes->render(). $text);
unset($PLUGINS_DIRECTORY);
}
function importLink()
{
$sql = e107::getDb();
$tp = e107::getParser();
$log = e107::getLog();
foreach($_POST['importid'] as $import)
{
list($name, $url, $type, $table, $id) = explode("^", $import);
$insert = array(
'gsitemap_id' => 0,
'gsitemap_name' => $tp->toDB($name),
'gsitemap_url' => $tp->toDB($url),
'gsitemap_table' => $tp->toDB($table),
'gsitemap_table_id' => (int) $id,
'gsitemap_lastmod' => time(),
'gsitemap_freq' => $_POST['import_freq'],
'gsitemap_priority' => $_POST['import_priority'],
'gsitemap_cat' => $type,
'gsitemap_order' => '0',
'gsitemap_img' => '',
'gsitemap_active' => '0',
);
$sql->insert("gsitemap", $insert);
// $sql->insert("gsitemap", "0, '$name', '$url', '".time()."', '".$_POST['import_freq']."', '".$_POST['import_priority']."', '$type', '0', '', '0' ");
}
$this->message = count($_POST['importid'])." link(s) imported.";
$log->add('GSMAP_01',$this->message);
}
function instructions()
{

View File

@ -40,37 +40,51 @@ class gsitemap_event // plugin-folder + '_event'
function update($data) // the method to run.
{
e107::getMessage()->addDebug("GSITEMAP TRIGGERRED!!") ;
// e107::getMessage()->addDebug("GSITEMAP TRIGGERRED!!") ;
if(empty($data['table']) || empty($data['newData']))
if(empty($data['plugin']) || empty($data['table']) || empty($data['newData']))
{
return null;
}
switch ($data['table'])
/** @var news_gsitemap $gsmap - could be another plugin too */
if(!$gsmap = e107::getAddon($data['plugin'], 'e_gsitemap'))
{
case "news":
$update = array(
'gsitemap_url' => e107::getUrl()->create('news/view/item', $data['newData'], array('full' => 1)),
'WHERE' => "gsitemap_table = 'news' AND gsitemap_table_id = ".(int) $data['id']
);
break;
case "page":
// code
break;
return null;
}
if(!empty($update))
if(!method_exists($gsmap, 'url'))
{
return null;
}
if(!$url = $gsmap->url($data['newData']))
{
return null;
}
$tp = e107::getParser();
$id = (int) $data['id'];
$update = array(
'gsitemap_url' => $url,
'WHERE' => "gsitemap_plugin = '".$tp->filter($data['plugin'])."'
AND gsitemap_table = '".$tp->filter($data['table'])."'
AND gsitemap_table_id = ".$id
);
// todo LAN
$message = e107::getParser()->lanVars("Updating sitemap link for #[x] to [y]. ", array($id,$url), true);
if(e107::getDb()->update('gsitemap', $update)!==false)
{
e107::getMessage()->addDebug("Gsitemap updated: ".print_a($update,true));
e107::getMessage()->addSuccess($message);
}
else
{
e107::getMessage()->addError($message);
}
}

View File

@ -1,10 +1,11 @@
CREATE TABLE gsitemap (
gsitemap_id int(11) unsigned NOT NULL auto_increment,
gsitemap_name varchar(200) NOT NULL default '',
gsitemap_url varchar(200) NOT NULL default '',
gsitemap_name varchar(200) NOT NULL,
gsitemap_url varchar(200) NOT NULL,
gsitemap_plugin varchar(50) NOT NULL default '',
gsitemap_table varchar(50) NOT NULL default '',
gsitemap_table_id int(7) NOT NULL default '0',
gsitemap_lastmod varchar(15) NOT NULL default '',
gsitemap_lastmod varchar(15) NOT NULL,
gsitemap_freq varchar(10) NOT NULL default '',
gsitemap_priority char(3) NOT NULL default '',
gsitemap_cat varchar(100) NOT NULL default '',

View File

@ -56,11 +56,24 @@ class news_gsitemap
'id' => $row['news_id'],
'table' => 'news',
'name' => $row['news_title'],
'url' => e107::getUrl()->create('news/view/item', $row, array('full' => 1)),
'url' => $this->url($row),
'type' => ADLAN_0
);
}
return $import;
}
/**
* Used above and by gsitemap/e_event.php to update the URL when changed in news, pages etc.
* @param $row
* @return string
*/
function url($row)
{
return e107::getUrl()->create('news/view/item', $row, array('full' => 1));
}
}