So I inherited a website that uses a bunch of PHP with zero comments explaining things. I am stuck on a function that is supposed to create links that modify the URI to look like a sub-directory rather than creating a physical resource underneath.
Here’s the function:
function getTabParams($link, $name){ global $modx; $params = array(); $typeValue = !empty($_GET['type']) ? strip_tags($_GET['type']) : ''; if(checkTabAvailability($link)){ $params = array( 'class' => ($typeValue == $link) ? 'active' : '', 'name' => $name, 'link' => !empty($link) ? $modx->resource->get('uri').($modx->resource->get('isfolder') == 1 ? '' : '/').$link : $modx->resource->get('uri') ); } return $params; }
The line in question is this:
'link' => !empty($link) ? $modx->resource->get('uri').($modx->resource->get('isfolder') == 1 ? '' : '/').$link : $modx->resource->get('uri')
Also, checkTabAvailability is a big block of code but here’s just one case for reference:
function checkTabAvailability($type){ global $modx; switch($type){ case 'people': $c = $modx->newQuery('modResource'); $c->leftJoin('modTemplateVarResource','TV1','TV1.contentid=modResource.id'); $c->where(array('template:IN' => [16,39,40], 'published' => 1, 'TV1.tmplvarid' => 81, 'TV1.value:LIKE' => '%'.$modx->resource->get('link_attributes').'%')); $c->select(array('modResource.id as id')); if(!$modx->getCount('modResource', $c)){ return false; } return true; break; default: // all return true; } }
For some reason only a handful of templates will successfully link to these “pages”. But if I’m building my own template or if I duplicate the template, it will not link properly. Just ends with a 404 page.
Anybody have any thoughts? Thanks