public function testStripPathChars() { $testSet = array('' => '', NULL => NULL, 'civicrm' => 'civicrm', 'civicrm/dashboard' => 'civicrm/dashboard', 'civicrm/contribute/transact' => 'civicrm/contribute/transact', 'civicrm/<hack>attempt</hack>' => 'civicrm/_hack_attempt_/hack_', 'civicrm dashboard & force = 1,;' => 'civicrm_dashboard___force___1__'); foreach ($testSet as $in => $expected) { $out = CRM_Utils_String::stripPathChars($in); $this->assertEquals($out, $expected, "Output does not match"); } }
/** * Generate an internal CiviCRM URL (copied from DRUPAL/includes/common.inc#url) * * @param $path string The path being linked to, such as "civicrm/add" * @param $query string A query string to append to the link. * @param $absolute boolean Whether to force the output to be an absolute link (beginning with http:). * Useful for links that will be displayed outside the site, such as in an * RSS feed. * @param $fragment string A fragment identifier (named anchor) to append to the link. * @param $htmlize boolean whether to convert to html eqivalant * @param $frontend boolean a gross joomla hack * * @return string an HTML string containing a link to the given path. * @access public * */ function url($path = NULL, $query = NULL, $absolute = FALSE, $fragment = NULL, $htmlize = TRUE, $frontend = FALSE, $forceBackend = FALSE) { $config = CRM_Core_Config::singleton(); $script = ''; $separator = $htmlize ? '&' : '&'; $pageID = ''; $path = CRM_Utils_String::stripPathChars($path); //this means wp function we are trying to use is not available, //so load bootStrap if (!function_exists('get_option')) { $this->loadBootStrap(); } $permlinkStructure = get_option('permalink_structure'); if ($config->userFrameworkFrontend) { if ($permlinkStructure != '') { global $post; $script = get_permalink($post->ID); } // when shortcode is included in page // also make sure we have valid query object global $wp_query; if (method_exists($wp_query, 'get')) { if (get_query_var('page_id')) { $pageID = "{$separator}page_id=" . get_query_var('page_id'); } elseif (get_query_var('p')) { // when shortcode is inserted in post $pageID = "{$separator}p=" . get_query_var('p'); } } } if (isset($fragment)) { $fragment = '#' . $fragment; } if (!isset($config->useFrameworkRelativeBase)) { $base = parse_url($config->userFrameworkBaseURL); $config->useFrameworkRelativeBase = $base['path']; } $base = $absolute ? $config->userFrameworkBaseURL : $config->useFrameworkRelativeBase; if (is_admin() && !$frontend || $forceBackend) { $base .= 'wp-admin/admin.php'; } elseif (defined('CIVICRM_UF_WP_BASEPAGE')) { $base .= CIVICRM_UF_WP_BASEPAGE; } elseif (isset($config->wpBasePage)) { $base .= $config->wpBasePage; } if (isset($path)) { if (isset($query)) { if ($permlinkStructure != '' && ($pageID || $script != '')) { return $script . '?page=CiviCRM' . $separator . 'q=' . $path . $pageID . $separator . $query . $fragment; } else { return $base . '?page=CiviCRM' . $separator . 'q=' . $path . $pageID . $separator . $query . $fragment; } } else { if ($permlinkStructure != '' && ($pageID || $script != '')) { return $script . '?page=CiviCRM' . $separator . 'q=' . $path . $pageID . $fragment; } else { return $base . '?page=CiviCRM' . $separator . 'q=' . $path . $pageID . $fragment; } } } else { if (isset($query)) { if ($permlinkStructure != '' && ($pageID || $script != '')) { return $script . '?' . $query . $pageID . $fragment; } else { return $base . $script . '?' . $query . $pageID . $fragment; } } else { return $base . $fragment; } } }
/** * Generate an internal CiviCRM URL (copied from DRUPAL/includes/common.inc#url) * * @param $path string The path being linked to, such as "civicrm/add" * @param $query string A query string to append to the link. * @param $absolute boolean Whether to force the output to be an absolute link (beginning with http:). * Useful for links that will be displayed outside the site, such as in an * RSS feed. * @param $fragment string A fragment identifier (named anchor) to append to the link. * @param $htmlize boolean whether to convert to html eqivalant * @param $frontend boolean a gross joomla hack * * @return string an HTML string containing a link to the given path. * @access public * */ function url($path = NULL, $query = NULL, $absolute = FALSE, $fragment = NULL, $htmlize = TRUE, $frontend = FALSE) { $config = CRM_Core_Config::singleton(); $script = 'index.php'; $path = CRM_Utils_String::stripPathChars($path); if (isset($fragment)) { $fragment = '#' . $fragment; } if (!isset($config->useFrameworkRelativeBase)) { $base = parse_url($config->userFrameworkBaseURL); $config->useFrameworkRelativeBase = $base['path']; } $base = $absolute ? $config->userFrameworkBaseURL : $config->useFrameworkRelativeBase; $separator = $htmlize ? '&' : '&'; if (!$config->cleanURL) { if (isset($path)) { if (isset($query)) { return $base . $script . '?q=' . $path . $separator . $query . $fragment; } else { return $base . $script . '?q=' . $path . $fragment; } } else { if (isset($query)) { return $base . $script . '?' . $query . $fragment; } else { return $base . $fragment; } } } else { if (isset($path)) { if (isset($query)) { return $base . $path . '?' . $query . $fragment; } else { return $base . $path . $fragment; } } else { if (isset($query)) { return $base . $script . '?' . $query . $fragment; } else { return $base . $fragment; } } } }
/** * @inheritDoc */ public function url($path = NULL, $query = NULL, $absolute = FALSE, $fragment = NULL, $frontend = FALSE, $forceBackend = FALSE) { $config = CRM_Core_Config::singleton(); $script = ''; $separator = '&'; $wpPageParam = ''; $fragment = isset($fragment) ? '#' . $fragment : ''; $path = CRM_Utils_String::stripPathChars($path); //this means wp function we are trying to use is not available, //so load bootStrap if (!function_exists('get_option')) { $this->loadBootStrap(); // FIXME: Why bootstrap in url()? Generally want to define 1-2 strategic places to put bootstrap } if ($config->userFrameworkFrontend) { if (get_option('permalink_structure') != '') { global $post; $script = get_permalink($post->ID); } // when shortcode is included in page // also make sure we have valid query object global $wp_query; if (method_exists($wp_query, 'get')) { if (get_query_var('page_id')) { $wpPageParam = "page_id=" . get_query_var('page_id'); } elseif (get_query_var('p')) { // when shortcode is inserted in post $wpPageParam = "p=" . get_query_var('p'); } } } $base = $this->getBaseUrl($absolute, $frontend, $forceBackend); if (!isset($path) && !isset($query)) { // FIXME: This short-circuited codepath is the same as the general one below, except // in that it ignores "permlink_structure" / $wpPageParam / $script . I don't know // why it's different (and I can only find two obvious use-cases for this codepath, // of which at least one looks gratuitous). A more ambitious person would simply remove // this code. return $base . $fragment; } if (!$forceBackend && get_option('permalink_structure') != '' && ($wpPageParam || $script != '')) { $base = $script; } $queryParts = array(); if (isset($path)) { $queryParts[] = 'page=CiviCRM'; $queryParts[] = "q={$path}"; } if ($wpPageParam) { $queryParts[] = $wpPageParam; } if (isset($query)) { $queryParts[] = $query; } return $base . '?' . implode($separator, $queryParts) . $fragment; }
/** * @inheritDoc */ public function url($path = NULL, $query = NULL, $absolute = FALSE, $fragment = NULL, $htmlize = TRUE, $frontend = FALSE, $forceBackend = FALSE) { $config = CRM_Core_Config::singleton(); $separator = $htmlize ? '&' : '&'; $Itemid = ''; $script = ''; $path = CRM_Utils_String::stripPathChars($path); if ($config->userFrameworkFrontend) { $script = 'index.php'; if (JRequest::getVar("Itemid")) { $Itemid = "{$separator}Itemid=" . JRequest::getVar("Itemid"); } } if (isset($fragment)) { $fragment = '#' . $fragment; } $base = $absolute ? $config->userFrameworkBaseURL : $config->useFrameworkRelativeBase; if (!empty($query)) { $url = "{$base}{$script}?option=com_civicrm{$separator}task={$path}{$Itemid}{$separator}{$query}{$fragment}"; } else { $url = "{$base}{$script}?option=com_civicrm{$separator}task={$path}{$Itemid}{$fragment}"; } // gross hack for joomla, we are in the backend and want to send a frontend url if ($frontend && $config->userFramework == 'Joomla') { // handle both joomla v1.5 and v1.6, CRM-7939 $url = str_replace('/administrator/index2.php', '/index.php', $url); $url = str_replace('/administrator/index.php', '/index.php', $url); // CRM-8215 $url = str_replace('/administrator/', '/index.php', $url); } elseif ($forceBackend) { if (defined('JVERSION')) { $joomlaVersion = JVERSION; } else { $jversion = new JVersion(); $joomlaVersion = $jversion->getShortVersion(); } if (version_compare($joomlaVersion, '1.6') >= 0) { $url = str_replace('/index.php', '/administrator/index.php', $url); } } return $url; }