2006-12-02 04:36:16 +00:00
< ? php
/*
2010-10-26 07:41:20 +00:00
* e107 website system
*
2017-01-14 16:08:13 +00:00
* Copyright ( C ) 2008 - 2017 e107 Inc ( e107 . org )
2010-10-26 07:41:20 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* Site navigation administration
*
*/
2021-01-16 13:32:35 -08:00
require_once ( __DIR__ . '/../class2.php' );
2017-01-17 01:33:03 +01:00
2009-12-02 22:34:15 +00:00
if ( ! getperms ( " I " ))
2009-11-23 11:51:02 +00:00
{
2016-01-13 19:17:37 -08:00
e107 :: redirect ( 'admin' );
2009-11-23 11:51:02 +00:00
exit ;
}
2006-12-02 04:36:16 +00:00
2011-05-18 14:04:12 +00:00
e107 :: coreLan ( 'links' , true );
2008-12-16 11:05:36 +00:00
2016-05-20 19:06:30 -07:00
e107 :: css ( 'inline' , " td .label-warning { margin-left:30px } " );
2012-05-16 06:05:39 +00:00
2006-12-02 04:36:16 +00:00
2009-11-23 11:51:02 +00:00
class links_admin extends e_admin_dispatcher
{
2008-12-16 11:05:36 +00:00
2009-11-23 11:51:02 +00:00
protected $modes = array (
'main' => array (
'controller' => 'links_admin_ui' ,
'path' => null ,
'ui' => 'links_admin_form_ui' ,
'uipath' => null
2009-12-02 22:34:15 +00:00
)
);
2009-11-23 11:51:02 +00:00
protected $adminMenu = array (
2013-02-22 22:34:04 -08:00
'main/list' => array ( 'caption' => LAN_MANAGE , 'perm' => 'I' ),
'main/create' => array ( 'caption' => LAN_CREATE , 'perm' => 'I' ),
2009-11-23 11:51:02 +00:00
'main/prefs' => array ( 'caption' => LAN_OPTIONS , 'perm' => 'I' ),
2015-06-10 14:37:10 -07:00
'main/tools' => array ( 'caption' => LINKLAN_4 , 'perm' => 'I' )
2009-11-23 11:51:02 +00:00
);
protected $adminMenuAliases = array (
2009-12-02 22:34:15 +00:00
'main/edit' => 'main/list'
);
2020-12-27 14:28:19 -08:00
protected $menuTitle = LAN_NAVIGATION ;
2017-02-01 18:25:32 -08:00
protected $adminMenuIcon = 'e-links-24' ;
2009-11-23 11:51:02 +00:00
}
2008-12-16 11:05:36 +00:00
2009-11-23 11:51:02 +00:00
class links_admin_ui extends e_admin_ui
2009-12-02 22:34:15 +00:00
{
2021-03-17 23:44:32 +01:00
protected $pluginTitle = LAN_NAVIGATION ;
2011-05-18 14:04:12 +00:00
protected $pluginName = 'core' ;
protected $table = " links " ;
protected $listQry = '' ;
protected $pid = " link_id " ;
protected $perPage = 0 ;
protected $batchDelete = true ;
2011-07-25 02:41:49 +00:00
protected $batchCopy = true ;
2022-03-10 13:13:48 -08:00
protected $batchExport = true ;
2012-12-15 18:06:55 -08:00
protected $listOrder = 'link_category,link_order ASC' ;
2013-04-02 10:07:15 +03:00
protected $sortField = 'link_order' ;
2013-02-26 17:18:37 -08:00
//FIXME TOOD - Filter out 'unassigned' entries by default.
2011-05-18 14:04:12 +00:00
public $current_parent = 0 ;
public $sublink_data = null ;
protected $fields = array (
2017-01-14 16:08:13 +00:00
'checkboxes' => array ( 'title' => '' , 'width' => '3%' , 'forced' => true , 'thclass' => 'center first' , 'class' => 'center first' ),
2017-03-14 12:00:20 -07:00
'link_button' => array ( 'title' => LAN_ICON , 'type' => 'icon' , 'width' => '5%' , 'thclass' => 'center' , 'class' => 'center' , 'readParms' => array ( 'legacy' => '{e_IMAGE}icons/' ), 'writeParms' => 'glyphs=1' ),
2017-01-14 16:08:13 +00:00
'link_id' => array ( 'title' => LAN_ID , 'type' => 'method' , 'readParms' => '' , 'noedit' => TRUE ),
2017-03-15 16:49:55 -07:00
'link_name' => array ( 'title' => LAN_NAME , 'type' => 'text' , 'inline' => true , 'required' => false , 'validate' => false , 'width' => 'auto' , 'writeParms' => array ( 'size' => 'xlarge' )), // not required as only an icon may be used.
'link_category' => array ( 'title' => LAN_TEMPLATE , 'type' => 'dropdown' , 'inline' => true , 'batch' => true , 'filter' => true , 'width' => 'auto' , 'writeParms' => array ( 'size' => 'xlarge' )),
2017-01-14 16:08:13 +00:00
2017-03-15 16:49:55 -07:00
'link_parent' => array ( 'title' => LAN_PARENT , 'type' => 'method' , 'data' => 'int' , 'width' => 'auto' , 'batch' => true , 'filter' => true , 'thclass' => 'left first' , 'writeParms' => array ( 'size' => 'xlarge' )),
2015-03-31 10:21:50 -07:00
'link_url' => array ( 'title' => LAN_URL , 'width' => 'auto' , 'type' => 'method' , 'inline' => true , 'required' => true , 'validate' => true , 'writeParms' => 'size=xxlarge' ),
2015-05-01 17:54:44 +02:00
'link_sefurl' => array ( 'title' => LAN_SEFURL , 'type' => 'method' , 'inline' => false , 'width' => 'auto' , 'help' => LCLAN_107 ),
2013-02-22 00:50:16 -08:00
'link_class' => array ( 'title' => LAN_USERCLASS , 'type' => 'userclass' , 'inline' => true , 'writeParms' => 'classlist=public,guest,nobody,member,classes,admin,main' , 'batch' => true , 'filter' => true , 'width' => 'auto' ),
2013-02-22 22:34:04 -08:00
'link_description' => array ( 'title' => LAN_DESCRIPTION , 'type' => 'textarea' , 'width' => 'auto' ), // 'method'=>'tinymce_plugins', ?
2013-04-02 10:07:15 +03:00
'link_order' => array ( 'title' => LAN_ORDER , 'type' => 'number' , 'width' => 'auto' , 'nolist' => false , 'inline' => true ),
2017-03-15 16:49:55 -07:00
'link_open' => array ( 'title' => LCLAN_19 , 'type' => 'dropdown' , 'inline' => true , 'width' => 'auto' , 'batch' => true , 'filter' => true , 'thclass' => 'left first' , 'writeParms' => array ( 'size' => 'xlarge' )),
2021-09-28 08:13:27 -07:00
'link_rel' => array ( 'title' => LAN_RELATIONSHIP , 'type' => 'tags' , 'inline' => true , 'width' => 'auto' , 'batch' => false , 'filter' => false , 'thclass' => 'left' , 'help' => LAN_RELATIONSHIP_HELP , 'writeParms' => array ( 'placeholder' => 'eg.nofollow,noreferrer' , 'size' => 'xlarge' )),
2021-09-27 10:22:14 -07:00
2015-05-01 17:54:44 +02:00
'link_function' => array ( 'title' => LCLAN_105 , 'type' => 'method' , 'data' => 'str' , 'width' => 'auto' , 'thclass' => 'left first' ),
2021-01-17 20:31:25 -08:00
'link_owner' => array ( 'title' => LCLAN_106 , 'type' => 'hidden' , 'filter' => true , 'data' => 'str' ),
2012-05-23 08:29:57 +00:00
'options' => array ( 'title' => LAN_OPTIONS , 'type' => null , 'forced' => TRUE , 'width' => '10%' , 'thclass' => 'center last' , 'class' => 'center' , 'readParms' => 'sort=1' ) // quick workaround
2011-05-18 14:04:12 +00:00
);
2009-11-26 09:02:46 +00:00
2015-06-09 18:03:53 -07:00
protected $fieldpref = array ( 'checkboxes' , 'link_button' , 'link_id' , 'link_name' , 'link_sefurl' , 'link_class' , 'link_category' , 'options' );
2009-12-02 22:34:15 +00:00
2011-05-18 14:04:12 +00:00
protected $prefs = array (
'linkpage_screentip' => array ( 'title' => LCLAN_78 , 'type' => 'boolean' , 'help' => LCLAN_79 ),
'sitelinks_expandsub' => array ( 'title' => LCLAN_80 , 'type' => 'boolean' , 'help' => LCLAN_81 )
);
2009-12-02 22:34:15 +00:00
2011-05-18 14:04:12 +00:00
/**
* Runtime cache of all links array
* @ var array
*/
protected $_link_array = null ;
2013-05-04 01:38:37 -07:00
2020-12-18 19:55:12 -08:00
function afterCreate ( $new_data , $old_data , $id ) //FIXME needs to work after inline editing too.
2013-05-04 01:38:37 -07:00
{
e107 :: getCache () -> clearAll ( 'content' );
}
2020-12-18 19:55:12 -08:00
function afterUpdate ( $new_data , $old_data , $id ) //FIXME needs to work after inline editing too.
2013-05-04 01:38:37 -07:00
{
e107 :: getCache () -> clearAll ( 'content' );
}
2009-12-02 22:34:15 +00:00
2009-11-26 09:02:46 +00:00
function init ()
{
2017-03-15 16:49:55 -07:00
$this -> fields [ 'link_category' ][ 'writeParms' ][ 'optArray' ] = array (
2021-03-17 02:14:04 +01:00
1 => LCLAN_112 ,
2 => LCLAN_113 ,
3 => LCLAN_114 ,
4 => " 4 - " . LCLAN_115 ,
5 => " 5 - " . LCLAN_115 ,
6 => " 6 - " . LCLAN_115 , // If more than 6 are required, then something is not right with the themeing method.
2012-12-15 18:06:55 -08:00
// 7 => "7 - Alt",
// 8 => "8 - Alt",
// 9 => "9 - Alt",
// 10 => "10 - Alt"
2021-03-17 02:14:04 +01:00
255 => LCLAN_116
2009-11-26 09:02:46 +00:00
);
2009-12-02 22:34:15 +00:00
2017-03-15 16:49:55 -07:00
$this -> fields [ 'link_open' ][ 'writeParms' ][ 'optArray' ] = array (
2009-11-26 09:02:46 +00:00
0 => LCLAN_20 , // 0 = same window
1 => LCLAN_23 , // new window
4 => LCLAN_24 , // 4 = miniwindow 600x400
5 => LINKLAN_1 // 5 = miniwindow 800x600
);
2015-06-04 17:01:27 -07:00
2009-11-26 09:02:46 +00:00
}
2015-06-04 17:01:27 -07:00
2012-01-13 11:47:39 +00:00
public function handleListLinkParentBatch ( $selected , $value )
2009-11-26 09:02:46 +00:00
{
2011-05-18 14:04:12 +00:00
$field = 'link_parent' ;
$ui = $this -> getUI ();
2012-01-13 11:47:39 +00:00
$found = false ;
2011-05-18 14:04:12 +00:00
foreach ( $selected as $k => $id )
2012-12-11 19:42:55 -08:00
{
// var_dump($ui->_has_parent($value, $id, $this->getLinkArray()));
2012-01-13 11:47:39 +00:00
if ( $ui -> _has_parent ( $value , $id , $this -> getLinkArray ()))
2009-11-26 09:02:46 +00:00
{
2011-05-18 14:04:12 +00:00
unset ( $selected [ $k ]);
2012-01-13 11:47:39 +00:00
$found = true ;
2009-11-26 09:02:46 +00:00
}
}
2015-05-01 17:54:44 +02:00
if ( $found ) e107 :: getMessage () -> addWarning ( LCLAN_108 );
2011-05-18 14:04:12 +00:00
if ( ! $selected ) return ;
2012-01-13 11:47:39 +00:00
2011-05-18 14:04:12 +00:00
if ( parent :: handleListBatch ( $selected , $field , $value ))
{
$this -> _link_array = null ; // reset batch/filters
return true ;
}
return false ;
2009-11-26 09:02:46 +00:00
}
2011-05-18 14:04:12 +00:00
public function ListObserver ()
{
$searchFilter = $this -> _parseFilterRequest ( $this -> getRequest () -> getQuery ( 'filter_options' , '' ));
2009-11-26 09:02:46 +00:00
2011-05-18 14:04:12 +00:00
if ( $searchFilter && in_array ( 'link_parent' , $searchFilter ))
{
$this -> getTreeModel () -> current_id = intval ( $searchFilter [ 1 ]);
$this -> current_parent = intval ( $searchFilter [ 1 ]);
}
2021-01-17 20:31:25 -08:00
$this -> fields [ 'link_owner' ][ 'type' ] = 'method' ;
2011-05-18 14:04:12 +00:00
parent :: ListObserver ();
2009-11-26 09:02:46 +00:00
2011-05-18 14:04:12 +00:00
}
2021-01-17 20:31:25 -08:00
2011-05-18 14:04:12 +00:00
public function ListAjaxObserver ()
{
$searchFilter = $this -> _parseFilterRequest ( $this -> getRequest () -> getQuery ( 'filter_options' , '' ));
2009-11-26 09:02:46 +00:00
2011-05-18 14:04:12 +00:00
if ( $searchFilter && in_array ( 'link_parent' , $searchFilter ))
{
$this -> getTreeModel () -> current_id = intval ( $searchFilter [ 1 ]);
$this -> current_parent = intval ( $searchFilter [ 1 ]);
}
parent :: ListAjaxObserver ();
}
2009-11-26 09:02:46 +00:00
2011-05-18 14:04:12 +00:00
/**
* Form submitted - 'etrigger_generate_sublinks' POST variable caught
2016-03-08 09:32:52 -08:00
*//*
2011-05-18 14:04:12 +00:00
public function SublinksGenerateSublinksTrigger ()
2008-09-23 19:37:36 +00:00
{
2011-05-18 14:04:12 +00:00
$this -> generateSublinks ();
}
2008-12-16 11:05:36 +00:00
2011-05-18 14:04:12 +00:00
public function sublinksObserver ()
{
$this -> getTreeModel () -> load ();
2016-03-08 09:32:52 -08:00
} */
2008-12-16 11:05:36 +00:00
2011-05-18 14:04:12 +00:00
/**
* Sublinks generator
*/
2015-06-04 17:01:27 -07:00
public function toolsPage ()
2011-05-18 14:04:12 +00:00
{
2016-03-08 09:32:52 -08:00
if ( ! empty ( $_POST [ 'etrigger_generate_sublinks' ]))
{
$this -> generateSublinks ( $_POST );
}
2011-05-18 14:04:12 +00:00
$sublinks = $this -> sublink_data ();
$ui = $this -> getUI ();
// TODO - use UI create form
$sql = e107 :: getDb ();
2008-12-15 22:32:24 +00:00
$text = "
2011-05-18 14:04:12 +00:00
< form method = 'post' action = '".e_REQUEST_URL."' >
2008-12-15 22:32:24 +00:00
< fieldset id = 'core-links-generator' >
< legend class = 'e-hideme' > " .LINKLAN_4. " </ legend >
2012-11-26 14:41:32 -08:00
< table class = 'table adminform' >
2012-05-13 05:50:32 +00:00
< colgroup >
< col class = 'col-label' />
< col class = 'col-control' />
2008-12-15 22:32:24 +00:00
</ colgroup >
< tbody >
< tr >
2013-03-21 13:39:11 +01:00
< td > " .LINKLAN_6. " :</ td >
2012-11-26 14:41:32 -08:00
< td >
2011-05-18 14:04:12 +00:00
" ;
2008-12-15 22:32:24 +00:00
foreach ( $sublinks as $key => $type )
{
2011-05-18 14:04:12 +00:00
$optarrayp [ $key ] = $type [ 'title' ];
//$selected = $this->getPosted('sublink_type') == $key ? ' selected="selected"' : '';
/* $text .= "
< option value = '{$key}' { $selected } > " . $type['title'] . " </ option >
" ;*/
2008-12-15 22:32:24 +00:00
}
2020-12-22 14:48:28 -08:00
$text .= $ui -> select ( 'sublink_type' , $optarrayp , $this -> getPosted ( 'sublink_type' ), '' , true );
2011-05-18 14:04:12 +00:00
2008-12-15 22:32:24 +00:00
$text .= "
</ td >
</ tr >
< tr >
2016-03-08 09:32:52 -08:00
< td > " .LINKLAN_7. " ( " .LAN_OPTIONAL. " ) </ td >
2012-11-26 14:41:32 -08:00
< td >
2011-05-18 14:04:12 +00:00
" ;
$text .= $ui -> link_parent ( $this -> getPosted ( 'link_parent' ), 'write' );
2008-12-15 22:32:24 +00:00
$text .= "
2011-05-18 14:04:12 +00:00
2008-12-15 22:32:24 +00:00
</ td >
</ tr >
</ tbody >
</ table >
< div class = 'buttons-bar center' >
2011-05-18 14:04:12 +00:00
" . $ui->admin_button ('etrigger_generate_sublinks', 'no-value', 'submit', LINKLAN_5). "
2008-12-15 22:32:24 +00:00
</ div >
</ fieldset >
</ form >
" ;
2015-06-10 14:37:10 -07:00
2009-11-23 11:51:02 +00:00
//$e107->ns->tablerender(LINKLAN_4, $emessage->render().$text);
2015-06-04 17:01:27 -07:00
// $this->addTitle(LINKLAN_4);
2015-06-10 14:37:10 -07:00
return $text ;
2015-06-04 17:01:27 -07:00
2006-12-02 04:36:16 +00:00
}
2008-12-16 11:05:36 +00:00
2015-06-04 17:01:27 -07:00
2011-05-18 14:04:12 +00:00
function sublink_data ( $name = " " )
2008-09-23 19:37:36 +00:00
{
2011-05-18 14:04:12 +00:00
if ( null !== $this -> sublink_data ) return ( $name ? $this -> sublink_data [ $name ] : $this -> sublink_data );
$sublink_type = array ();
2008-12-15 22:32:24 +00:00
$sublink_type [ 'news' ][ 'title' ] = LINKLAN_8 ; // "News Categories";
$sublink_type [ 'news' ][ 'table' ] = " news_category " ;
$sublink_type [ 'news' ][ 'query' ] = " category_id !='-2' ORDER BY category_name ASC " ;
2016-03-08 13:53:58 -08:00
$sublink_type [ 'news' ][ 'url' ] = " news.php?list.# " ;
2008-12-15 22:32:24 +00:00
$sublink_type [ 'news' ][ 'fieldid' ] = " category_id " ;
$sublink_type [ 'news' ][ 'fieldname' ] = " category_name " ;
$sublink_type [ 'news' ][ 'fieldicon' ] = " category_icon " ;
2016-03-08 13:53:58 -08:00
$sublink_type [ 'news' ][ 'sef' ] = " news/list/category " ;
$sublink_type [ 'newsalt' ] = $sublink_type [ 'news' ];
$sublink_type [ 'newsalt' ][ 'url' ] = " news.php?cat.# " ;
$sublink_type [ 'newsalt' ][ 'title' ] = LINKLAN_8 . " ( " . LAN_LIST . " ) " ; // "News Categories";
$sublink_type [ 'newsalt' ][ 'sef' ] = " news/list/short " ;
2008-12-16 11:05:36 +00:00
2008-12-15 22:32:24 +00:00
$sublink_type [ 'downloads' ][ 'title' ] = LINKLAN_9 ; //"Download Categories";
$sublink_type [ 'downloads' ][ 'table' ] = " download_category " ;
$sublink_type [ 'downloads' ][ 'query' ] = " download_category_parent ='0' ORDER BY download_category_name ASC " ;
$sublink_type [ 'downloads' ][ 'url' ] = " download.php?list.# " ;
$sublink_type [ 'downloads' ][ 'fieldid' ] = " download_category_id " ;
$sublink_type [ 'downloads' ][ 'fieldname' ] = " download_category_name " ;
$sublink_type [ 'downloads' ][ 'fieldicon' ] = " download_category_icon " ;
2008-12-16 11:05:36 +00:00
2011-05-18 14:04:12 +00:00
// fixed - sql query not needed
$plugins = array_keys ( e107 :: getConfig () -> get ( 'plug_installed' ));
2008-12-16 11:05:36 +00:00
2011-05-18 14:04:12 +00:00
foreach ( $plugins as $plugin )
2008-12-15 22:32:24 +00:00
{
2011-05-18 14:04:12 +00:00
if ( is_readable ( e_PLUGIN . $plugin . '/e_linkgen.php' ))
2008-12-15 22:32:24 +00:00
{
2011-05-18 14:04:12 +00:00
require_once ( e_PLUGIN . $plugin . '/e_linkgen.php' );
2008-12-15 22:32:24 +00:00
}
}
2011-05-18 14:04:12 +00:00
$this -> sublink_data = $sublink_type ;
2008-12-15 22:32:24 +00:00
if ( $name )
{
return $sublink_type [ $name ];
}
2008-12-16 11:05:36 +00:00
2008-12-15 22:32:24 +00:00
return $sublink_type ;
2006-12-02 04:36:16 +00:00
}
2009-11-26 09:02:46 +00:00
2011-05-18 14:04:12 +00:00
function generateSublinks ( $sublink )
{
$mes = e107 :: getMessage ();
$subtype = $this -> getPosted ( 'sublink_type' ); //$_POST['sublink_type'];
$pid = intval ( $this -> getPosted ( 'link_parent' ));
$sublink = $this -> sublink_data ( $subtype );
2020-12-18 19:55:12 -08:00
// if(!$pid)
// {
2016-03-08 09:32:52 -08:00
// $mes->addWarning(LCLAN_109);
// return;
2020-12-18 19:55:12 -08:00
// }
2011-05-18 14:04:12 +00:00
if ( ! $subtype )
{
2016-03-08 09:32:52 -08:00
$mes -> addWarning ( LCLAN_110 );
2011-05-18 14:04:12 +00:00
return ;
}
if ( ! $sublink )
{
2016-03-08 09:32:52 -08:00
$mes -> addError ( LCLAN_111 );
2011-05-18 14:04:12 +00:00
return ;
}
2009-11-26 09:02:46 +00:00
2011-05-18 14:04:12 +00:00
$sublink = $this -> sublink_data ( $subtype );
2009-11-26 09:02:46 +00:00
2011-05-18 14:04:12 +00:00
$sql = e107 :: getDb ();
$sql2 = e107 :: getDb ( 'sql2' );
2009-12-02 22:34:15 +00:00
2016-03-08 09:32:52 -08:00
$sql -> select ( " links " , " * " , " link_id= " . $pid );
$par = $sql -> fetch ();
2009-12-02 22:34:15 +00:00
2011-05-18 14:04:12 +00:00
//extract($par);
// Added option for passing of result array
if ( vartrue ( $sublink [ 'result' ]))
{
$count = 1 ;
foreach ( $sublink [ 'result' ] as $row )
{
$subcat = $row [( $sublink [ 'fieldid' ])];
$name = $row [( $sublink [ 'fieldname' ])];
$subname = $name ; // eliminate old embedded hierarchy from names. (e.g. 'submenu.TopName.name')
2016-03-08 13:53:58 -08:00
if ( ! empty ( $sublink [ 'sef' ]))
{
$suburl = e107 :: url ( $sublink [ 'sef' ], $row );
}
else
{
$suburl = str_replace ( " # " , $subcat , $sublink [ 'url' ]);
}
2011-05-18 14:04:12 +00:00
$subicon = ( $sublink [ 'fieldicon' ]) ? $row [( $sublink [ 'fieldicon' ])] : $par [ 'link_button' ];
$subdiz = ( $sublink [ 'fielddiz' ]) ? $row [( $sublink [ 'fielddiz' ])] : $par [ 'link_description' ];
$subparent = $pid ;
2009-12-02 22:34:15 +00:00
2011-05-18 14:04:12 +00:00
$insert_array = array (
'link_name' => $subname ,
'link_url' => $suburl ,
'link_description' => $subdiz ,
'link_button' => $subicon ,
'link_category' => $par [ 'link_category' ],
'link_order' => $count ,
'link_parent' => $subparent ,
'link_open' => $par [ 'link_open' ],
'link_class' => $par [ 'link_class' ],
'link_function' => ''
);
$count ++ ;
}
}
else
{
2016-03-08 09:32:52 -08:00
$sql -> select ( $sublink [ 'table' ], " * " , $sublink [ 'query' ]);
2009-11-23 11:51:02 +00:00
$count = 1 ;
2016-03-08 09:32:52 -08:00
while ( $row = $sql -> fetch ())
2009-11-23 11:51:02 +00:00
{
$subcat = $row [( $sublink [ 'fieldid' ])];
$name = $row [( $sublink [ 'fieldname' ])];
$subname = $name ; // eliminate old embedded hierarchy from names. (e.g. 'submenu.TopName.name')
2016-03-08 13:53:58 -08:00
if ( ! empty ( $sublink [ 'sef' ]))
{
$suburl = e107 :: url ( $sublink [ 'sef' ], $row );
}
else
{
$suburl = str_replace ( " # " , $subcat , $sublink [ 'url' ]);
}
2011-05-18 14:04:12 +00:00
$subicon = ( $sublink [ 'fieldicon' ]) ? $row [( $sublink [ 'fieldicon' ])] : $par [ 'link_button' ];
$subdiz = ( $sublink [ 'fielddiz' ]) ? $row [( $sublink [ 'fielddiz' ])] : $par [ 'link_description' ];
$subparent = $pid ;
2009-12-02 22:34:15 +00:00
$insert_array = array (
2009-11-23 11:51:02 +00:00
'link_name' => $subname ,
'link_url' => $suburl ,
'link_description' => $subdiz ,
'link_button' => $subicon ,
2016-03-08 09:32:52 -08:00
'link_category' => vartrue ( $par [ 'link_category' ], 1 ),
2009-11-23 11:51:02 +00:00
'link_order' => $count ,
'link_parent' => $subparent ,
2011-05-18 14:04:12 +00:00
'link_open' => $par [ 'link_open' ],
2016-03-08 09:32:52 -08:00
'link_class' => intval ( $par [ 'link_class' ]),
2009-11-23 11:51:02 +00:00
'link_function' => ''
2009-12-02 22:34:15 +00:00
);
2016-03-08 13:53:58 -08:00
e107 :: getMessage () -> addDebug ( print_a ( $insert_array , true ));
2016-03-08 09:32:52 -08:00
if ( $sql2 -> insert ( " links " , $insert_array ))
2009-11-23 11:51:02 +00:00
{
2016-03-08 09:32:52 -08:00
$message = LAN_CREATED . " ( { $name } )[!br!] " ;
$mes -> addSuccess ( LAN_CREATED . " ( { $name } ) " );
2009-11-23 11:51:02 +00:00
} else
{
2016-03-08 09:32:52 -08:00
$message = LAN_CREATED_FAILED . " ( { $name } )[!br!] " ;
$mes -> addError ( LAN_CREATED_FAILED . " ( { $name } ) " );
2009-11-23 11:51:02 +00:00
}
$count ++ ;
}
2011-05-18 14:04:12 +00:00
}
2020-12-18 19:55:12 -08:00
2011-05-18 14:04:12 +00:00
}
/**
* Product tree model
2020-12-18 19:55:12 -08:00
* @ return links_admin_ui | links_model_admin_tree
2011-05-18 14:04:12 +00:00
*/
public function _setTreeModel ()
{
$this -> _tree_model = new links_model_admin_tree ();
return $this ;
}
2009-12-02 22:34:15 +00:00
2011-05-18 14:04:12 +00:00
/**
* Link ordered array
* @ return array
*/
public function getLinkArray ( $current_id = 0 )
{
if ( null === $this -> _link_array )
{
if ( $this -> getAction () != 'list' )
2009-11-23 11:51:02 +00:00
{
2019-06-03 16:29:38 -07:00
$this -> getTreeModel () -> setParam ( 'order' , 'ORDER BY ' . $this -> listOrder ) -> loadBatch ();
2009-11-23 11:51:02 +00:00
}
2019-06-03 16:29:38 -07:00
/** @var e_tree_modell $tree */
2011-05-18 14:04:12 +00:00
$tree = $this -> getTreeModel () -> getTree ();
$this -> _link_array = array ();
foreach ( $tree as $id => $model )
{
if ( $current_id == $id ) continue ;
$this -> _link_array [ $model -> get ( 'link_parent' )][ $id ] = $model -> get ( 'link_name' );
}
asort ( $this -> _link_array );
}
return $this -> _link_array ;
2009-12-02 22:34:15 +00:00
}
2009-11-23 11:51:02 +00:00
}
2008-12-16 11:05:36 +00:00
2011-05-18 14:04:12 +00:00
class links_model_admin_tree extends e_admin_tree_model
2009-11-23 11:51:02 +00:00
{
2011-05-18 14:04:12 +00:00
public $modify = false ;
public $current_id = 0 ;
2009-12-02 22:34:15 +00:00
2011-05-18 14:04:12 +00:00
protected $_db_table = 'links' ;
protected $_link_array = null ;
protected $_link_array_modified = null ;
2010-01-12 16:14:08 +00:00
2011-05-18 14:04:12 +00:00
protected $_field_id = 'link_id' ;
/**
* Get array of models
* Custom tree order
* @ return array
*/
function getTree ( $force = false )
2009-11-23 11:51:02 +00:00
{
2011-05-18 14:04:12 +00:00
return $this -> getOrderedTree ( $this -> modify );
}
2009-12-02 22:34:15 +00:00
2011-05-18 14:04:12 +00:00
/**
* Get ordered by their parents models
* @ return array
*/
function getOrderedTree ( $modified = false )
{
$var = ! $modified ? '_link_array' : '_link_array_modified' ;
if ( null === $this -> $var )
2010-01-12 16:14:08 +00:00
{
2011-05-18 14:04:12 +00:00
$tree = $this -> get ( '__tree' , array ());
$this -> $var = array ();
$search = array ();
foreach ( $tree as $id => $model )
2010-01-12 16:14:08 +00:00
{
2011-05-18 14:04:12 +00:00
$search [ $model -> get ( 'link_parent' )][ $id ] = $model ;
2010-01-12 16:14:08 +00:00
}
2011-05-18 14:04:12 +00:00
asort ( $search );
$this -> _tree_order ( $this -> current_id , $search , $this -> $var , 0 , $modified );
2010-01-12 16:14:08 +00:00
}
2011-05-18 14:04:12 +00:00
//$this->buildTreeIndex();
return $this -> $var ;
2008-11-02 10:15:37 +00:00
}
2009-12-02 22:34:15 +00:00
2011-05-18 14:04:12 +00:00
/**
* Reorder current tree
* @ param $parent_id
* @ param $search
* @ param $src
2021-12-03 14:58:33 -08:00
* @ param int $level
* @ param bool $modified
2011-05-18 14:04:12 +00:00
* @ return void
*/
function _tree_order ( $parent_id , $search , & $src , $level = 0 , $modified = false )
2009-12-02 22:34:15 +00:00
{
2011-05-18 14:04:12 +00:00
if ( ! isset ( $search [ $parent_id ]))
2009-12-02 22:34:15 +00:00
{
2011-05-18 14:04:12 +00:00
return ;
2009-11-23 11:51:02 +00:00
}
2011-05-18 14:04:12 +00:00
$level_image = $level ? '<img src="' . e_IMAGE_ABS . 'generic/branchbottom.gif" class="icon" alt="" style="margin-left: ' . ( $level * 20 ) . 'px" /> ' : '' ;
foreach ( $search [ $parent_id ] as $model )
2009-11-23 11:51:02 +00:00
{
2011-05-18 14:04:12 +00:00
$id = $model -> get ( 'link_id' );
$src [ $id ] = $model ;
if ( $modified )
{
2013-06-10 17:55:43 +03:00
$model -> set ( 'link_name' , $this -> bcClean ( $model -> get ( 'link_name' )))
-> set ( 'link_indent' , $level_image );
2011-05-18 14:04:12 +00:00
}
$this -> _tree_order ( $id , $search , $src , $level + 1 , $modified );
2009-11-23 11:51:02 +00:00
}
}
2013-05-06 15:21:06 -07:00
function bcClean ( $link_name )
{
if ( substr ( $link_name , 0 , 8 ) == 'submenu.' ) // BC Fix.
{
list ( $tmp , $tmp2 , $link ) = explode ( '.' , $link_name , 3 );
}
else
{
$link = $link_name ;
}
return $link ;
}
2011-05-18 14:04:12 +00:00
}
2008-12-16 11:05:36 +00:00
2006-12-02 04:36:16 +00:00
2011-05-18 14:04:12 +00:00
class links_admin_form_ui extends e_admin_form_ui
{
protected $current_parent = null ;
2011-06-17 01:13:05 +00:00
private $linkFunctions ;
2021-01-17 20:31:25 -08:00
private $link_owner = array ();
2011-06-17 01:13:05 +00:00
function init ()
{
2012-12-12 21:30:43 -08:00
$tp = e107 :: getParser ();
2013-02-26 03:43:52 -08:00
$tmp = e107 :: getAddonConfig ( 'e_sitelink' , 'sitelink' );
2013-10-28 21:30:24 -07:00
2011-06-17 01:13:05 +00:00
foreach ( $tmp as $cat => $array )
{
$func = array ();
foreach ( $array as $val )
{
$newkey = $cat . '::' . $val [ 'function' ];
2013-10-28 21:30:24 -07:00
if ( vartrue ( $val [ 'parm' ]))
{
$newkey .= " ( " . $val [ 'parm' ] . " ) " ;
}
2019-02-26 12:22:36 -08:00
$func [ $newkey ] = $tp -> toHTML ( $val [ 'name' ], '' , 'TITLE' );
2011-06-17 01:13:05 +00:00
}
$this -> linkFunctions [ $cat ] = $func ;
}
2017-03-15 16:49:55 -07:00
$sitetheme = e107 :: getPref ( 'sitetheme' );
if ( ! file_exists ( e_THEME . $sitetheme . '/theme_shortcodes.php' ))
{
return null ;
}
require_once ( e_THEME . $sitetheme . '/theme_shortcodes.php' );
$methods = get_class_methods ( 'theme_shortcodes' );
asort ( $methods );
$cat = defset ( 'LINKLAN_10' , " Theme Shortcodes " );
foreach ( $methods as $func )
{
if ( strpos ( $func , 'sc_' ) !== 0 )
{
continue ;
}
$newkey = 'theme::' . $func ;
$this -> linkFunctions [ $cat ][ $newkey ] = str_replace ( 'sc_' , '' , $func );
}
2021-01-17 20:31:25 -08:00
if ( $tmp = e107 :: getDb () -> retrieve ( 'links' , 'link_owner' , " GROUP BY link_owner ORDER BY link_owner " , true ))
{
foreach ( $tmp as $arr )
{
if ( empty ( $arr [ 'link_owner' ]))
{
continue ;
}
2017-03-15 16:49:55 -07:00
2021-01-17 20:31:25 -08:00
$plug = $arr [ 'link_owner' ];
// $def = 'LAN_PLUGIN_'.strtoupper($plug).'_NAME';
$this -> link_owner [ $plug ] = $plug ;
}
}
2017-03-15 16:49:55 -07:00
2011-06-17 01:13:05 +00:00
}
2011-05-18 14:04:12 +00:00
function link_parent ( $value , $mode )
{
switch ( $mode )
{
case 'read' :
$current = $this -> getController () -> current_parent ;
if ( $current ) // show only one parent
{
if ( null === $this -> current_parent )
{
2020-12-14 16:21:48 -08:00
if ( e107 :: getDb () -> select ( 'links' , 'link_name' , 'link_id=' . $current ))
2011-05-18 14:04:12 +00:00
{
2020-12-14 16:21:48 -08:00
$tmp = e107 :: getDb () -> fetch ();
2011-05-18 14:04:12 +00:00
$this -> current_parent = $tmp [ 'link_name' ];
}
}
}
$cats = $this -> getController () -> getLinkArray ();
$ret = array ();
$this -> _parents ( $value , $cats , $ret );
if ( $this -> current_parent ) array_unshift ( $ret , $this -> current_parent );
return ( $ret ? implode ( ' » ' , $ret ) : '-' );
break ;
case 'write' :
$catid = $this -> getController () -> getId ();
$cats = $this -> getController () -> getLinkArray ( $catid );
$ret = array ();
$this -> _parent_select_array ( 0 , $cats , $ret );
2020-12-22 14:48:28 -08:00
return $this -> select ( 'link_parent' , $ret , $value , array ( 'size' => 'xlarge' , 'default' => LAN_SELECT . " ... " ));
2011-05-18 14:04:12 +00:00
break ;
case 'batch' :
case 'filter' :
$cats = $this -> getController () -> getLinkArray ();
$ret [ 0 ] = $mode == 'batch' ? 'REMOVE PARENT' : 'Main Only' ;
$this -> _parent_select_array ( 0 , $cats , $ret );
return $ret ;
break ;
}
}
2009-11-23 11:51:02 +00:00
2011-06-17 01:13:05 +00:00
function link_function ( $curVal , $mode )
{
if ( $mode == 'read' )
{
return $curVal ; // $this->linkFunctions[$curVal];
}
if ( $mode == 'write' )
{
2020-12-22 14:48:28 -08:00
return $this -> select ( 'link_function' , $this -> linkFunctions , $curVal , array ( 'size' => 'xlarge' , 'default' => " ( " . LAN_OPTIONAL . " ) " ));
2011-06-17 01:13:05 +00:00
}
else
{
return $this -> linkFunctions ;
}
}
2015-03-31 10:21:50 -07:00
2015-04-01 22:59:25 -07:00
function link_id ( $curVal , $mode )
{
if ( $mode == 'read' )
{
$linkUrl = $this -> getController () -> getListModel () -> get ( 'link_url' );
2016-06-10 08:19:02 -07:00
2016-06-10 08:33:39 -07:00
$url = $this -> link_url ( $linkUrl , 'link_id' );
2016-06-10 08:19:02 -07:00
2015-04-01 22:59:25 -07:00
return " <a href=' " . $url . " ' rel='external'> " . $curVal . " </a> " ; // $this->linkFunctions[$curVal];
}
}
2015-03-31 10:21:50 -07:00
2021-01-17 20:31:25 -08:00
function link_owner ( $curVal , $mode )
{
if ( $mode == 'read' )
{
return $curVal ;
}
if ( $mode === 'filter' )
{
return $this -> link_owner ;
}
}
2015-03-31 10:21:50 -07:00
function link_sefurl ( $curVal , $mode )
{
if ( $mode == 'read' )
{
2015-04-01 22:59:25 -07:00
$plugin = $this -> getController () -> getModel () -> get ( 'link_owner' );
2015-03-31 10:21:50 -07:00
return $curVal ; // $this->linkFunctions[$curVal];
}
if ( $mode == 'write' )
{
$plugin = $this -> getController () -> getModel () -> get ( 'link_owner' );
$obj = e107 :: getAddon ( $plugin , 'e_url' );
$config = e107 :: callMethod ( $obj , 'config' );
$opts = array ();
if ( empty ( $config ))
{
2015-05-01 17:54:44 +02:00
return $this -> hidden ( 'link_sefurl' , '' ) . " <span class='label label-warning'> " . LAN_NOT_AVAILABLE . " </span> " ;
2015-03-31 10:21:50 -07:00
}
foreach ( $config as $k => $v )
{
2016-06-27 18:03:09 -07:00
if ( $k == 'index' || ( strpos ( $v [ 'regex' ], '(' ) === false )) // only provide urls without dynamic elements.
2015-03-31 10:21:50 -07:00
{
$opts [] = $k ;
}
}
2016-05-20 19:06:30 -07:00
sort ( $opts );
2015-03-31 10:21:50 -07:00
return $this -> select ( 'link_sefurl' , $opts , $curVal , array ( 'useValues' => true , 'defaultValue' => '' , 'default' => '(' . LAN_DISABLED . ')' ));
}
}
function link_url ( $curVal , $mode )
{
2016-06-10 08:33:39 -07:00
if ( $mode == 'read' || $mode == 'link_id' ) // read = display mode, link_id = actual absolute URL
2015-03-31 10:21:50 -07:00
{
$owner = $this -> getController () -> getListModel () -> get ( 'link_owner' );
$sef = $this -> getController () -> getListModel () -> get ( 'link_sefurl' );
2016-06-10 08:33:39 -07:00
if ( $curVal [ 0 ] !== '{' && substr ( $curVal , 0 , 4 ) != 'http' && $mode == 'link_id' )
2016-06-10 08:19:02 -07:00
{
$curVal = '{e_BASE}' . $curVal ;
}
2015-03-31 10:21:50 -07:00
if ( ! empty ( $owner ) && ! empty ( $sef ))
{
2016-06-10 08:33:39 -07:00
$opt = ( $mode == 'read' ) ? array ( 'mode' => 'raw' ) : array ();
$curVal = e107 :: url ( $owner , $sef , null , $opt );
2015-03-31 10:21:50 -07:00
}
2016-06-10 08:19:02 -07:00
else
{
2016-06-10 08:33:39 -07:00
$opt = ( $mode == 'read' ) ? 'rel' : 'abs' ;
$curVal = e107 :: getParser () -> replaceConstants ( $curVal , $opt );
2016-06-10 08:19:02 -07:00
}
e107 :: getDebug () -> log ( $curVal );
2015-03-31 10:21:50 -07:00
return $curVal ; // $this->linkFunctions[$curVal];
}
if ( $mode == 'write' )
{
$owner = $this -> getController () -> getModel () -> get ( 'link_owner' );
$sef = $this -> getController () -> getModel () -> get ( 'link_sefurl' );
if ( ! empty ( $owner ) && ! empty ( $sef ))
{
$text = str_replace ( e_HTTP , '' , e107 :: url ( $owner , $sef )); // dynamically created.
$text .= $this -> hidden ( 'link_url' , $curVal );
2015-05-01 17:54:44 +02:00
$text .= " <span class='label label-warning'> " . LAN_AUTO_GENERATED . " </span> " ;
2015-03-31 10:21:50 -07:00
return $text ;
}
return $this -> text ( 'link_url' , $curVal , 255 , array ( 'size' => 'xxlarge' ));
}
if ( $mode == 'inline' )
{
$sef = $this -> getController () -> getListModel () -> get ( 'link_sefurl' );
if ( empty ( $sef ))
{
return array ( 'inlineType' => 'text' );
}
return false ;
}
}
2011-06-17 01:13:05 +00:00
2011-05-18 14:04:12 +00:00
/**
*
* @ param integer $category_id
* @ param array $search
* @ param array $src
* @ param boolean $titles
* @ return array
*/
function _parents ( $link_id , $search , & $src , $titles = true )
2009-11-23 11:51:02 +00:00
{
2011-05-18 14:04:12 +00:00
foreach ( $search as $parent => $cat )
2009-11-23 11:51:02 +00:00
{
2011-05-18 14:04:12 +00:00
if ( $cat && array_key_exists ( $link_id , $cat ))
{
array_unshift ( $src , ( $titles ? $cat [ $link_id ] : $link_id ));
if ( $parent > 0 )
{
$this -> _parents ( $parent , $search , $src , $titles );
}
}
2009-11-23 11:51:02 +00:00
}
2011-05-18 14:04:12 +00:00
}
2009-12-02 22:34:15 +00:00
2011-05-18 14:04:12 +00:00
function _parent_select_array ( $parent_id , $search , & $src , $strpad = ' ' , $level = 0 )
{
if ( ! isset ( $search [ $parent_id ]))
2011-05-01 15:22:25 +00:00
{
2011-05-18 14:04:12 +00:00
return ;
2009-11-23 11:51:02 +00:00
}
2009-12-02 22:34:15 +00:00
2011-05-18 14:04:12 +00:00
foreach ( $search [ $parent_id ] as $id => $title )
2008-12-15 22:32:24 +00:00
{
2011-05-18 14:04:12 +00:00
$src [ $id ] = str_repeat ( $strpad , $level ) . ( $level != 0 ? '- ' : '' ) . $title ;
$this -> _parent_select_array ( $id , $search , $src , $strpad , $level + 1 );
2008-12-15 22:32:24 +00:00
}
}
2009-12-02 22:34:15 +00:00
2011-05-18 14:04:12 +00:00
function _has_parent ( $link_id , $parent_id , $cats )
{
$path = array ();
$this -> _parents ( $link_id , $cats , $path , false );
return in_array ( $parent_id , $path );
}
2013-06-10 17:55:43 +03:00
/**
* New core feature - triggered before values are rendered
*/
function renderValueTrigger ( & $field , & $value , & $params , $id )
{
if ( $field !== 'link_name' ) return ;
$tree = $this -> getController () -> getTreeModel ();
// notify we need modified tree
$tree -> modify = true ;
//retrieve array of data models
$data = $tree -> getTree ();
// retrieve the propper model by id
$model = varset ( $data [ $id ]);
if ( ! $model ) return ;
// Add indent as 'pre' parameter
$params [ 'pre' ] = $model -> get ( 'link_indent' );
}
2008-11-02 10:15:37 +00:00
2011-05-18 14:04:12 +00:00
/**
* Override Create list view
*
* @ return string
*/
2020-06-26 13:58:59 -07:00
public function getList ( $ajax = false , $view = 'default' )
2011-05-18 14:04:12 +00:00
{
$tp = e107 :: getParser ();
$controller = $this -> getController ();
$request = $controller -> getRequest ();
$id = $this -> getElementId ();
$tree = $options = array ();
$tree [ $id ] = clone $controller -> getTreeModel ();
$tree [ $id ] -> modify = true ;
2013-06-10 17:55:43 +03:00
2011-05-18 14:04:12 +00:00
// if going through confirm screen - no JS confirm
$controller -> setFieldAttr ( 'options' , 'noConfirm' , $controller -> deleteConfirmScreen );
2022-03-10 13:13:48 -08:00
$coreBatchOptions = array (
'delete' => $controller -> getBatchDelete (),
'copy' => $controller -> getBatchCopy (),
'url' => $controller -> getBatchLink (),
'featurebox' => $controller -> getBatchFeaturebox (),
'export' => $controller -> getBatchExport (),
);
2011-05-18 14:04:12 +00:00
$options [ $id ] = array (
'id' => $this -> getElementId (), // unique string used for building element ids, REQUIRED
'pid' => $controller -> getPrimaryName (), // primary field name, REQUIRED
//'url' => e_SELF, default
//'query' => $request->buildQueryString(array(), true, 'ajax_used'), - ajax_used is now removed from QUERY_STRING - class2
'head_query' => $request -> buildQueryString ( 'field=[FIELD]&asc=[ASC]&from=[FROM]' , false ), // without field, asc and from vars, REQUIRED
'np_query' => $request -> buildQueryString ( array (), false , 'from' ), // without from var, REQUIRED for next/prev functionality
'legend' => $controller -> getPluginTitle (), // hidden by default
'form_pre' => ! $ajax ? $this -> renderFilter ( $tp -> post_toForm ( array ( $controller -> getQuery ( 'searchquery' ), $controller -> getQuery ( 'filter_options' ))), $controller -> getMode () . '/' . $controller -> getAction ()) : '' , // needs to be visible when a search returns nothing
'form_post' => '' , // markup to be added after closing form element
'fields' => $controller -> getFields (), // see e_admin_ui::$fields
'fieldpref' => $controller -> getFieldPref (), // see e_admin_ui::$fieldpref
'table_pre' => '' , // markup to be added before opening table element
2022-03-10 13:13:48 -08:00
'table_post' => ! $tree [ $id ] -> isEmpty () ? $this -> renderBatch ( $coreBatchOptions , $controller -> getBatchOptions ()) : '' ,
2011-05-18 14:04:12 +00:00
'fieldset_pre' => '' , // markup to be added before opening fieldset element
'fieldset_post' => '' , // markup to be added after closing fieldset element
'perPage' => $controller -> getPerPage (), // if 0 - no next/prev navigation
'from' => $controller -> getQuery ( 'from' , 0 ), // current page, default 0
'field' => $controller -> getQuery ( 'field' ), //current order field name, default - primary field
'asc' => $controller -> getQuery ( 'asc' , 'desc' ), //current 'order by' rule, default 'asc'
);
//$tree[$id]->modify = false;
return $this -> renderListForm ( $options , $tree , $ajax );
}
2006-12-02 04:36:16 +00:00
}
2009-11-23 11:51:02 +00:00
new links_admin ();
2008-12-16 11:05:36 +00:00
2009-11-23 11:51:02 +00:00
require_once ( e_ADMIN . " auth.php " );
e107 :: getAdminUI () -> runPage ();
// TODO Link Preview. (similar to userclass preview)
/*
echo " <h2>Preview (To-Do)</h2> " ;
echo $tp -> parseTemplate ( " { SITELINKS_ALT} " );
*/
require_once ( e_ADMIN . " footer.php " );
2021-01-16 13:32:35 -08:00
2009-11-23 11:51:02 +00:00
2008-12-16 11:05:36 +00:00
2007-06-05 20:07:35 +00:00
2006-12-02 04:36:16 +00:00
2008-12-15 22:32:24 +00:00
2016-09-27 11:31:47 +02:00
?>