/** * Tagify a string * * @param string $data Tagify * * @return string Tagified string */ protected function tagify($data) { $name = $this->getFullName(true, false); $params = $this->getParams(); $listModel = $this->getlistModel(); $filters = $listModel->getFilterArray(); $fkeys = JArrayHelper::getValue($filters, 'key', array()); $data = explode(",", strip_tags($data)); $tags = array(); $url = $params->get('textarea_tagifyurl'); if ($url == '') { $url = $_SERVER['REQUEST_URI']; $bits = explode('?', $url); $root = JArrayHelper::getValue($bits, 0, '', 'string'); $bits = JArrayHelper::getValue($bits, 1, '', 'string'); $bits = explode("&", $bits); $fullName = $this->getFullName(true, false); for ($b = count($bits) - 1; $b >= 0; $b--) { $parts = explode("=", $bits[$b]); if (count($parts) > 1) { $key = FabrikString::ltrimword(FabrikString::safeColNameToArrayKey($parts[0]), '&'); if ($key == $fullName) { unset($bits[$b]); } if ($key == $fullName . '[value]') { unset($bits[$b]); } if ($key == $fullName . '[condition]') { unset($bits[$b]); } } } } $url = $root . '?' . implode('&', $bits); // $$$ rob 24/02/2011 remove duplicates from tags $data = array_unique($data); $img = FabrikWorker::j3() ? 'bookmark.png' : 'tag.png'; $icon = FabrikHelperHTML::image($img, 'form', @$this->tmpl, array('alt' => 'tag')); foreach ($data as $d) { $d = trim($d); if ($d != '') { if (trim($params->get('textarea_tagifyurl')) == '') { $qs = strstr($url, '?'); if (substr($url, -1) === '?') { $thisurl = $url . $name . '[value]=' . $d; } else { $thisurl = strstr($url, '?') ? $url . '&' . $name . '[value]=' . urlencode($d) : $url . '?' . $name . '[value]=' . urlencode($d); } $thisurl .= '&' . $name . '[condition]=CONTAINS'; $thisurl .= '&resetfilters=1'; } else { $thisurl = str_replace('{tag}', urlencode($d), $url); } $tags[] = '<a href="' . $thisurl . '" class="fabrikTag">' . $icon . $d . '</a>'; } } return implode(' ', $tags); }
/** * Does a file exist * * @param string $filepath File path to test * * @return bool */ public function exists($filepath) { if ($filepath == '\\') { return false; } if (JFile::exists($filepath)) { return true; } $filepath = COM_FABRIK_BASE . '/' . FabrikString::ltrimword($filepath, COM_FABRIK_BASE . '/'); return JFile::exists($filepath); }
/** * Does a file exist * * @param string $filepath File path to test * @param bool $prependRoot also test with root prepended * * @return bool */ public function exists($filepath, $prependRoot = true) { if (empty($filepath) || $filepath == '\\') { return false; } if (JFile::exists($filepath)) { return true; } if ($prependRoot) { $filepath = COM_FABRIK_BASE . '/' . FabrikString::ltrimword($filepath, COM_FABRIK_BASE . '/'); return JFile::exists($filepath); } return false; }
function _strToCoords($v, $zoomlevel = 0) { $o = new stdClass(); $o->coords = array('', ''); $o->zoomlevel = (int) $zoomlevel; if (strstr($v, ",")) { $ar = explode(":", $v); $o->zoomlevel = count($ar) == 2 ? array_pop($ar) : 4; $v = FabrikString::ltrimword($ar[0], "("); $v = rtrim($v, ")"); $o->coords = explode(",", $v); } else { $o->coords = array(0, 0); } return $o; }
/** * tagify a string * @param string to tagify * @return string tagified string */ protected function tagify($data) { $name = $this->getFullName(false, true, false); $params = $this->getParams(); $listModel = $this->getlistModel(); $filters = $listModel->getFilterArray(); $fkeys = JArrayHelper::getValue($filters, 'key', array()); $data = explode(",", strip_tags($data)); $tags = array(); $url = $params->get('textarea_tagifyurl'); if ($url == '') { $url = $_SERVER['REQUEST_URI']; $bits = explode('?', $url); $bits = JArrayHelper::getValue($bits, 1, '', 'string'); $bits = explode("&", $bits); foreach ($bits as $bit) { $parts = explode("=", $bit); if (count($parts) > 1) { $key = FabrikString::ltrimword(FabrikString::safeColNameToArrayKey($parts[0]), '&'); if ($key == $this->getFullName(false, true, false)) { $url = str_replace($key . '=' . $parts[1], '', $url); } } } } // $$$ rbo 24/02/2011 remove duplicates from tags $data = array_unique($data); $icon = FabrikHelperHTML::image('tag.png', 'form', @$this->tmpl, array('alt' => 'tag')); foreach ($data as $d) { $d = trim($d); if ($d != '') { if (trim($params->get('textarea_tagifyurl')) == '') { $qs = strstr($url, '?'); if (substr($url, -1) === '?') { $thisurl = "{$url}{$name}={$d}"; } else { $thisurl = strstr($url, '?') ? "{$url}&{$name}=" . urlencode($d) : "{$url}?{$name}=" . urlencode($d); } } else { $thisurl = str_replace('{tag}', urlencode($d), $url); } $tags[] = '<a href="' . $thisurl . '" class="fabrikTag">' . $icon . $d . '</a>'; } } return implode(" ", $tags); }
/** * */ function _xmlExport($xml) { $archiveName = 'fabrik_package-' . $this->label; require_once JPATH_SITE . '/includes/Archive/Tar.php'; $archivePath = JPATH_SITE . '/components/com_fabrik/' . $archiveName . '.tgz'; if (JFile::exists($archivePath)) { @unlink($archivePath); } $zip = new Archive_Tar($archivePath); $fileName = $archiveName . '.xml'; $fileName = $this->_bufferFile; //$ok = $zip->addModify('/tmp/' . $fileName, '', "/tmp/"); //, '', dirname( $fileName) . "/" $fileName = str_replace(JPATH_SITE, '', $this->_bufferFile); $fileName = FabrikString::ltrimword($fileName, "/administrator/"); $ok = $zip->addModify($fileName, '', "components/com_fabrik"); for ($i = 0; $i < count($this->_aFiles); $i++) { $this->_aFiles[$i] = JPATH_SITE . '/components/com_fabrik/tmpl/' . $this->_aFiles[$i]; } $zip->addModify($this->_aFiles, '', JPATH_SITE . '/components/com_fabrik'); $this->_output_file($archivePath, $archiveName . '.tgz'); }
/** * Get lists group by headings * * @return array heading names */ public function getGroupByHeadings() { $formModel = $this->getFormModel(); $input = $this->app->input; $base = JURI::getInstance(); $base = $base->toString(array('scheme', 'user', 'pass', 'host', 'port', 'path')); $qs = $input->server->get('QUERY_STRING', '', 'string'); if (JString::stristr($qs, 'group_by')) { $qs = FabrikString::removeQSVar($qs, 'group_by'); $qs = FabrikString::ltrimword($qs, '?'); $qs = str_replace('&', '&', $qs); } $url = $base; if (!empty($qs)) { $url .= JString::strpos($url, '?') !== false ? '&' : '?'; $url .= $qs; } $url .= JString::strpos($url, '?') !== false ? '&' : '?'; $a = array(); list($h, $x, $b, $c) = $this->getHeadings(); $o = new stdClass(); $o->label = FText::_('COM_FABRIK_NONE'); $o->group_by = ''; $a[$url . 'group_by=0'] = $o; foreach ($h as $key => $v) { if (!in_array($key, array('fabrik_select', 'fabrik_edit', 'fabrik_view', 'fabrik_delete', 'fabrik_actions'))) { /** * $$$ hugh - other junk is showing up in $h, like 85___14-14-86_list_heading, or element * names ending in _form_heading. May not be the most efficient method, but we need to * test if $key exists as an element, as well as the simple in_array() test above. */ if ($formModel->hasElement($key, false, false)) { $thisUrl = $url . 'group_by=' . $key; $o = new stdClass(); $o->label = strip_tags($v); $o->group_by = $key; $a[$thisUrl] = $o; } } } return $a; }
/** * Create the where part for the query that selects the list options * * @param array $data Current row data to use in placeholder replacements * @param bool $incWhere Should the additional user defined WHERE statement be included * @param string $thisTableAlias Db table alias * @param array $opts Options * @param JDatabaseQuery $query Append where to JDatabaseQuery object or return string (false) * * @return string|JDatabaseQuery */ protected function buildQueryWhere($data = array(), $incWhere = true, $thisTableAlias = null, $opts = array(), $query = false) { $where = ''; $listModel = $this->getlistModel(); $params = $this->getParams(); $element = $this->getElement(); $whereaccess = $params->get('database_join_where_access', 26); $where = $this->mustApplyWhere($whereaccess, $element->id) && $incWhere ? $params->get('database_join_where_sql') : ''; $join = $this->getJoin(); $thisTableAlias = is_null($thisTableAlias) ? $join->table_join_alias : $thisTableAlias; // $$$rob 11/10/2011 remove order by statements which will be re-inserted at the end of buildQuery() if (preg_match('/(ORDER\\s+BY)(.*)/i', $where, $matches)) { $this->orderBy = str_replace("{thistable}", $join->table_join_alias, $matches[0]); $where = str_replace($this->orderBy, '', $where); $where = str_replace($matches[0], '', $where); } if (!empty($this->autocomplete_where)) { $mode = JArrayHelper::getValue($opts, 'mode', 'form'); $displayType = $params->get('database_join_display_type', 'dropdown'); $filterType = $element->filter_type; if ($mode == 'filter' && $filterType == 'auto-complete' || $mode == 'form' && $displayType == 'auto-complete' || $mode == 'filter' && $displayType == 'auto-complete') { $where .= JString::stristr($where, 'WHERE') ? ' AND ' . $this->autocomplete_where : ' WHERE ' . $this->autocomplete_where; } } if ($where == '') { return $query ? $query : $where; } $where = str_replace("{thistable}", $thisTableAlias, $where); $w = new FabrikWorker(); $lang = JFactory::getLanguage(); $data = is_array($data) ? $data : array(); if (!isset($data['lang'])) { $data['lang'] = $lang->getTag(); } $where = $w->parseMessageForPlaceHolder($where, $data, false); if (!$query) { return $where; } else { // $where = JString::str_ireplace('WHERE', '', $where); $where = FabrikString::ltrimword($where, 'WHERE', true); $query->where($where); return $query; } }
/** * Get base tag url * * @param string $fullName Full name (key value to remove from querystring) * * @return string */ public static function tagBaseUrl($fullName) { $url = $_SERVER['REQUEST_URI']; $bits = explode('?', $url); $root = JArrayHelper::getValue($bits, 0, '', 'string'); $bits = JArrayHelper::getValue($bits, 1, '', 'string'); $bits = explode("&", $bits); for ($b = count($bits) - 1; $b >= 0; $b--) { $parts = explode("=", $bits[$b]); if (count($parts) > 1) { $key = FabrikString::ltrimword(FabrikString::safeColNameToArrayKey($parts[0]), '&'); if ($key == $fullName) { unset($bits[$b]); } if ($key == $fullName . '[value]') { unset($bits[$b]); } if ($key == $fullName . '[condition]') { unset($bits[$b]); } } } $url = $root . '?' . implode('&', $bits); return $url; }
/** * Checks if the file can be uploaded * * @param array File information * @param string An error message to be returned * @return boolean */ function canUpload($file, &$err, &$params) { if (empty($file['name'])) { $err = 'Please input a file for upload'; return false; } if (!is_uploaded_file($file['tmp_name'])) { //handle potential malicous attack $err = JText::_('File has not been uploaded'); return false; } jimport('joomla.filesystem.file'); $format = strtolower(JFile::getExt($file['name'])); $allowable = explode(',', strtolower($params->get('ul_file_types'))); $format = FabrikString::ltrimword($format, '.'); $format2 = ".{$format}"; if (!in_array($format, $allowable) && !in_array($format2, $allowable)) { $err = 'WARNFILETYPE'; return false; } $maxSize = (int) $params->get('upload_maxsize', 0); if ($maxSize > 0 && (int) $file['size'] > $maxSize) { $err = 'WARNFILETOOLARGE'; return false; } $ignored = array(); $user = JFactory::getUser(); $imginfo = null; if ($params->get('restrict_uploads', 1)) { $images = explode(',', $params->get('image_extensions')); if (in_array($format, $images)) { // if its an image run it through getimagesize if (($imginfo = getimagesize($file['tmp_name'])) === FALSE) { $err = 'WARNINVALIDIMG'; return false; } } else { if (!in_array($format, $ignored)) { // if its not an image...and we're not ignoring it /*$allowed_mime = explode(',', $upload_mime); $illegal_mime = explode(',', $upload_mime_illegal); if (function_exists('finfo_open') && $params->get('check_mime',1)) { // We have fileinfo $finfo = finfo_open(FILEINFO_MIME); $type = finfo_file($finfo, $file['tmp_name']); if (strlen($type) && !in_array($type, $allowed_mime) && in_array($type, $illegal_mime)) { $err = 'WARNINVALIDMIME'; return false; } finfo_close($finfo); } else if (function_exists('mime_content_type') && $params->get('check_mime',1)) { // we have mime magic $type = mime_content_type($file['tmp_name']); if (strlen($type) && !in_array($type, $allowed_mime) && in_array($type, $illegal_mime)) { $err = 'WARNINVALIDMIME'; return false; } }*/ } } } $xss_check = JFile::read($file['tmp_name'], false, 256); $html_tags = array('abbr', 'acronym', 'address', 'applet', 'area', 'audioscope', 'base', 'basefont', 'bdo', 'bgsound', 'big', 'blackface', 'blink', 'blockquote', 'body', 'bq', 'br', 'button', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'comment', 'custom', 'dd', 'del', 'dfn', 'dir', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'fn', 'font', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'hr', 'html', 'iframe', 'ilayer', 'img', 'input', 'ins', 'isindex', 'keygen', 'kbd', 'label', 'layer', 'legend', 'li', 'limittext', 'link', 'listing', 'map', 'marquee', 'menu', 'meta', 'multicol', 'nobr', 'noembed', 'noframes', 'noscript', 'nosmartquotes', 'object', 'ol', 'optgroup', 'option', 'param', 'plaintext', 'pre', 'rt', 'ruby', 's', 'samp', 'script', 'select', 'server', 'shadow', 'sidebar', 'small', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'title', 'tr', 'tt', 'ul', 'var', 'wbr', 'xml', 'xmp', '!DOCTYPE', '!--'); foreach ($html_tags as $tag) { // A tag is '<tagname ', so we need to add < and a space or '<tagname>' if (JString::stristr($xss_check, '<' . $tag . ' ') || JString::stristr($xss_check, '<' . $tag . '>')) { $err = 'WARNIEXSS'; return false; } } return true; }
/** * run form & element plugins - yeah! * @param string method to check and call - corresponds to stage of form processing * @param object model calling the plugin form/table * @param string plugin type to call form/table * @return array of bools: false if error found and processed, otherwise true */ function runPlugins($method, &$oRequest, $type = 'form') { if ($type == 'form') { // $$$ rob allow for table plugins to hook into form plugin calls - methods are mapped as: //form method = 'onLoad' => table method => 'onFormLoad' $tmethod = 'onForm' . FabrikString::ltrimword($method, 'on'); $this->runPlugins($tmethod, $oRequest->getListModel(), 'list'); } $params =& $oRequest->getParams(); //$this->getPlugInGroup($type); $return = array(); $usedPlugins = (array) $params->get('plugins'); $usedLocations = (array) $params->get('plugin_locations'); $usedEvents = (array) $params->get('plugin_events'); $this->_data = array(); if ($type != 'list') { if (method_exists($oRequest, 'getGroupsHiarachy')) { $groups =& $oRequest->getGroupsHiarachy(); foreach ($groups as $groupModel) { $elementModels =& $groupModel->getPublishedElements(); foreach ($elementModels as $elementModel) { if (method_exists($elementModel, $method)) { $elementModel->{$method}($oRequest); } } } } } $c = 0; $runPlugins = 0; // if true then a plugin has returned true from runAway() which means that any other plugin in the same group // should not be run. $runningAway = false; foreach ($usedPlugins as $usedPlugin) { if ($runningAway) { // "I soiled my armour I was so scared!" break; } if ($usedPlugin != '') { $plugin = $this->getPlugIn($usedPlugin, $type); //testing this if statement as onLoad was being called on form email plugin when no method availbale $plugin->renderOrder = $c; if (method_exists($plugin, $method)) { $modelTable = $oRequest->getTable(); $pluginParams =& $plugin->setParams($params, $c); $location = JArrayHelper::getValue($usedLocations, $c); $event = JArrayHelper::getValue($usedEvents, $c); if ($plugin->canUse($oRequest, $location, $event) && method_exists($plugin, $method)) { $pluginArgs = array(); if (func_num_args() > 3) { $t =& func_get_args(); $pluginArgs =& array_splice($t, 3); } $preflightMethod = $method . "_preflightCheck"; $preflightCheck = method_exists($plugin, $preflightMethod) ? $plugin->{$preflightMethod}($pluginParams, $oRequest, $pluginArgs) : true; if ($preflightCheck) { $ok = $plugin->{$method}($pluginParams, $oRequest, $pluginArgs); if ($ok === false) { $return[] = false; } else { $thisreturn = $plugin->customProcessResult($method, $oRequest); $return[] = $thisreturn; $m = $method . '_result'; if (method_exists($plugin, $m)) { $this->_data[] = $plugin->{$m}($c); } } $runPlugins++; if ($plugin->runAway($method)) { $runningAway = true; } $mainData = $this->_data; if ($type == 'list' && $method !== 'observe') { $this->runPlugins('observe', $oRequest, 'list', $plugin, $method); } $this->_data = $mainData; } } } $c++; } } $this->_runPlugins = $runPlugins; return array_unique($return); }
/** * Get the js code to create the legend * * @return string */ public function getLegend() { $this->setupEvents(); $ref = $this->getJSRenderContext(); // @TODO: json encode the returned value and move to the view $aLegend = "{$ref}.addLegend(["; foreach ($this->events as $listId => $record) { $listModel = JModelLegacy::getInstance('list', 'FabrikFEModel'); $listModel->setId($listId); $table = $listModel->getTable(); foreach ($record as $data) { $rubbish = $table->db_table_name . '___'; $colour = FabrikString::ltrimword($data['colour'], $rubbish); $legend = FabrikString::ltrimword($data['legendtext'], $rubbish); $label = empty($legend) ? $table->label : $legend; $aLegend .= "{'label':'" . $label . "','colour':'" . $colour . "'},"; } } $aLegend = rtrim($aLegend, ",") . "]);"; return $aLegend; }
/** * Remove '-' from string * * @param string $str String to remove - from * * @return string */ protected function removeDashes($str) { $str = FabrikString::ltrimword($str, '-'); return $str; }
function getAdminJS() { $element =& $this->getElement(); $mooversion = FabrikWorker::getMooVersion() == 1 ? 1.2 : 1.1; $script = "\tvar fabrikdropdown = new fabrikAdminDropdown({'mooversion':'{$mooversion}'});\n" . "\tpluginControllers.push({element:'fabrikdropdown', controller: fabrikdropdown});\n"; $sub_values = explode("|", $element->sub_values); $sub_texts = explode("|", $element->sub_labels); $sub_intial_selections = explode("|", FabrikString::ltrimword($element->sub_intial_selection, '|')); $json = array(); for ($ii = 0; $ii < count($sub_values) && $ii < count($sub_texts); $ii++) { $bits = array(html_entity_decode($sub_values[$ii], ENT_QUOTES), html_entity_decode($sub_texts[$ii], ENT_QUOTES)); if (in_array($sub_values[$ii], $sub_intial_selections)) { $bits[] = 'checked'; } $json[] = $bits; } $script .= "\tfabrikdropdown.addSubElements(" . json_encode($json) . ");\n"; return $script; }
/** * Get lists group by headings * * @return array heading names */ public function getGroupByHeadings() { $base = JURI::getInstance(); $base = $base->toString(array('scheme', 'user', 'pass', 'host', 'port', 'path')); //$base .= JString::strpos($base, '?') ? '&' : '?'; $qs = JRequest::getVar('QUERY_STRING', '', 'server'); if (JString::stristr($qs, 'group_by')) { $qs = FabrikString::removeQSVar($qs, 'group_by'); $qs = FabrikString::ltrimword($qs, '?'); } $url = $base; if (!empty($qs)) { $url .= JString::strpos($url, '?') !== false ? '&' : '?'; $url .= $qs; } $url .= JString::strpos($url, '?') !== false ? '&' : '?'; $a = array(); list($h, $x, $b, $c) = $this->getHeadings(); $a[$url . 'group_by=0'] = JText::_('COM_FABRIK_NONE'); foreach ($h as $key => $v) { if (!in_array($key, array('fabrik_select', 'fabrik_edit', 'fabrik_view', 'fabrik_delete', 'fabrik_actions'))) { $thisurl = $url . 'group_by=' . $key; $a[$thisurl] = strip_tags($v); } } return $a; }
$shortName = JString::substr($option, 4); $query->select('id')->from('#__fabrik_packages')->where('(component_name = ' . $db->quote($option) . ' OR component_name = ' . $db->quote($shortName) . ') AND external_ref <> ""')->order('version DESC'); $db->setQuery($query, 0, 1); $id = $db->loadResult(); if ($id == '') { throw new RuntimeException('Fabrik: Could not load package', 500); } // Not 100% sure we need to set packageId now - most urls are now converted to com_{packagename} $input->set('packageId', $id); // Include dependencies jimport('joomla.application.component.controller'); jimport('joomla.application.component.model'); jimport('joomla.filesystem.file'); // Set the user state to load the package db tables $app = JFactory::getApplication(); $option = FabrikString::ltrimword($option, 'com_'); $app->setUserState('com_fabrik.package', $option); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_fabrik/tables'); JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_fabrik/models'); $controller = $input->getCmd('view'); $path = JPATH_SITE . '/components/com_fabrik/controllers/' . $controller . '.php'; if (JFile::exists($path)) { require_once $path; } else { $controller = ''; } $classname = 'FabrikController' . JString::ucfirst($controller); $config = array(); $config['base_path'] = JPATH_SITE . '/components/com_fabrik/'; /** * Create the controller if the task is in the form view.task then get
function delete($filepath) { //$filepath = $this->urlToPath($filepath); $filepath = FabrikString::ltrimword($filepath, $this->getS3BaseURL()); $filepath = ltrim($filepath, '/'); $this->s3->deleteObject($this->getBucketName(), $filepath); }
/** * should be called JUST before view is rendered (unless in admin when it should be called at end of view * ensures that incompatible versions of mootools are removed * and that if there is a combined js file it is loaded */ function cleanMootools() { $version = new JVersion(); global $combine; FabrikHelperHTML::_getCombine(); $app =& JFactory::getApplication(); $fbConfig =& JComponentHelper::getParams('com_fabrik'); if ($fbConfig->get('merge_js', false)) { $file = $combine->getCacheFile(); $combine->output(); $p = FabrikString::ltrimword(str_replace("\\", "/", str_replace(COM_FABRIK_BASE, '', $combine->outputFolder())), "/") . "/"; // $$$ rob DONT use FabrikHelper::Script here - this is the ONE place where we HAVE to use JHTML::Script JHTML::script($file, $p); } if ($version->RELEASE == '1.5' && $version->DEV_LEVEL >= 19) { if (JPluginHelper::isEnabled('system', 'mtupgrade')) { return; } } if (FabrikWorker::getMooVersion() == 1) { $document =& JFactory::getDocument(); $found = false; //new order for scripts $scripts = array(); //array of scripts to place first $aM2scripts = array('/js/archive/', '/components/com_fabrik/libs/mootools1.2/mootools-1.2.js', '/components/com_fabrik/libs/mootools1.2/mootools-1.2-uncompressed.js', '/components/com_fabrik/libs/mootools1.2/compat.js', '/components/com_fabrik/libs/mootools1.2/mootools-1.2-ext.js', '/components/com_fabrik/libs/mootools1.2/mootools-1.2-more.js', '/components/com_fabrik/libs/mootools1.2/mootools-1.2-more-uncompressed.js', '/components/com_fabrik/libs/mootools1.2/tips.js'); $docscripts = FabrikHelperHTML::getDocumentHeadPart('scripts'); foreach ($docscripts as $script => $type) { foreach ($aM2scripts as $ms) { if (strstr($script, $ms)) { $found = true; $scripts[$script] = $type; } } } if ($found) { $removescripts = array(); // $$$ hugh @TODO - need to fix this for >.5.19 with built in moo, otherwise // we are removing J!'s moo! So added the media/system/js/ path prefix. foreach ($docscripts as $script => $type) { if (strstr($script, 'media/system/js/mootools.js') || strstr($script, 'media/system/js/mootools-uncompressed.js') || strstr($script, 'mootools-release-1.11.js') || strstr($script, 'mootools.v1.1.js')) { $removescripts[$script] = $type; } } // $rob test shifting all the mootools1.2 scripts to the top of the doc head // fixes issue with jceutilities js script $first = array(); foreach ($document->_scripts as $script => $type) { foreach ($aM2scripts as $ms) { if (strstr($script, $ms)) { unset($document->_scripts[$script]); $first[$script] = $type; } } } $document->_scripts = $first + $document->_scripts; FabrikHelperHTML::removeDocumentHeadPart('scripts', $removescripts); } } }
echo $this->_row->class; ?> "><a href="<?php echo $this->_row->data->fabrik_view_url; ?> " class="noeffect"> <?php foreach ($this->headings as $heading => $label) { $d = $this->_row->data->{$heading}; if (JString::stristr($d, 'src=')) { $rawheading = $heading . "_raw"; if (!in_array($this->_row->data->{$rawheading}, array('0', '1'))) { //get the thumbnails url - cant use rawheading as that contains the path to the // full size image $bgimg = FabrikString::ltrimword(str_replace("\\", "/", $this->_row->data->{$rawheading}), '/'); $str = "<xml>" . $this->_row->data->{$heading} . "</xml>"; $xmlDoc =& JFactory::getXMLParser('DOM', array('lite' => false)); $xmlDoc->resolveErrors(true); $ok = $xmlDoc->parseXML($str, false); if ($ok) { $imgs =& $xmlDoc->getElementsByTagName('img'); $bgimg = str_replace(COM_FABRIK_LIVESITE, '', $imgs->item(0)->getAttribute('src')); } ?> <span class="image" style="background-image: url(<?php echo $bgimg; ?> );"></span> <?php break;
function getLegend() { $db = FabrikWorker::getDbo(); $params = $this->getParams(); $this->setupEvents(); $tables = (array) $params->get('calendar_table'); $colour = (array) $params->get('colour'); $calendar = $this->_row; $aLegend = "{$this->calName}.addLegend(["; $jsevents = array(); foreach ($this->_events as $listid => $record) { $listModel = JModel::getInstance('list', 'FabrikFEModel'); $listModel->setId($listid); $table = $listModel->getTable(); foreach ($record as $data) { $rubbish = $table->db_table_name . '___'; $colour = FabrikString::ltrimword($data['colour'], $rubbish); $aLegend .= "{'label':'" . $table->label . "','colour':'" . $colour . "'},"; } } $aLegend = rtrim($aLegend, ",") . "]);"; return $aLegend; }
/** * Run form & element plugins - yeah! * * @param string $method To check and call - corresponds to stage of form processing * @param object &$parentModel Model calling the plugin form/list * @param string $type Plugin type to call form/list * * @return array of bools: false if error found and processed, otherwise true */ public function runPlugins($method, &$parentModel, $type = 'form') { $profiler = JProfiler::getInstance('Application'); JDEBUG ? $profiler->mark("runPlugins: start: {$method}") : null; if ($type == 'form') { /** * $$$ rob allow for table plugins to hook into form plugin calls - methods are mapped as: * form method = 'onLoad' => table method => 'onFormLoad' */ $tmethod = 'onForm' . FabrikString::ltrimword($method, 'on'); $listModel = $parentModel->getListModel(); $this->runPlugins($tmethod, $listModel, 'list'); } $params = $parentModel->getParams(); $return = array(); $usedPlugins = (array) $params->get('plugins'); $usedLocations = (array) $params->get('plugin_locations'); $usedEvents = (array) $params->get('plugin_events'); $states = (array) $params->get('plugin_state'); $this->data = array(); if ($type != 'list') { if (method_exists($parentModel, 'getGroupsHiarachy')) { $groups = $parentModel->getGroupsHiarachy(); foreach ($groups as $groupModel) { $elementModels = $groupModel->getPublishedElements(); foreach ($elementModels as $elementModel) { if (method_exists($elementModel, $method)) { JDEBUG ? $profiler->mark("runPlugins: start element method: {$method}") : null; $elementModel->{$method}($parentModel); } } } } } $c = 0; $runPlugins = 0; /** * if true then a plugin has returned true from runAway() * which means that any other plugin in the same group should not be run. */ $runningAway = false; $mainData = array(); foreach ($usedPlugins as $usedPlugin) { if ($runningAway) { // "I soiled my armour I was so scared!" break; } $state = FArrayHelper::getValue($states, $c, 1); if ($state == false) { $c++; continue; } if ($usedPlugin != '') { $plugin = $this->getPlugIn($usedPlugin, $type); // Testing this if statement as onLoad was being called on form email plugin when no method available if (method_exists($plugin, $method)) { JDEBUG ? $profiler->mark("runPlugins: method_exists: {$plugin}, {$method}") : null; $plugin->renderOrder = $c; $modelTable = $parentModel->getTable(); $pluginParams = $plugin->setParams($params, $c); $location = FArrayHelper::getValue($usedLocations, $c); $event = FArrayHelper::getValue($usedEvents, $c); $plugin->setModel($parentModel); if ($plugin->canUse($location, $event)) { $pluginArgs = array(); if (func_num_args() > 3) { $t = func_get_args(); $pluginArgs = array_splice($t, 3); } $preflightMethod = $method . '_preflightCheck'; $preflightCheck = method_exists($plugin, $preflightMethod) ? $plugin->{$preflightMethod}($pluginArgs) : true; if ($preflightCheck) { JDEBUG ? $profiler->mark("runPlugins: preflight OK, starting: {$plugin}, {$method}") : null; $ok = $plugin->{$method}($pluginArgs); if ($ok === false) { $return[] = false; } else { $thisreturn = $plugin->customProcessResult($method); $return[] = $thisreturn; $m = $method . '_result'; if (method_exists($plugin, $m)) { $this->data[] = $plugin->{$m}($c); } } $runPlugins++; if ($plugin->runAway($method)) { $runningAway = true; } $mainData = $this->data; if ($type == 'list' && $method !== 'observe') { $this->runPlugins('observe', $parentModel, 'list', $plugin, $method); } $this->data = $mainData; } } } $c++; } } $this->runPlugins = $runPlugins; JDEBUG ? $profiler->mark("runPlugins: end: {$method}") : null; return array_unique($return); }
private function getCordsFromData($d) { $v = trim($d); $v = FabrikString::ltrimword($v, "("); if (strstr($v, ",")) { if (strstr($v, ":")) { $ar = explode(":", $v); array_pop($ar); $v = explode(",", $ar[0]); } else { $v = explode(",", $v); } $v[1] = FabrikString::rtrimword($v[1], ")"); } else { $v = array(0, 0); } return $v; }
/** * @param $key * @param $condition * @param $originalValue * @param $evalFilter * * @return string */ protected function filterQueryMultiValues($key, $condition, $originalValue, $evalFilter) { $str = array(); if ($evalFilter) { $originalValue = stripslashes(htmlspecialchars_decode($originalValue, ENT_QUOTES)); $originalValue = @eval($originalValue); FabrikWorker::logEval($originalValue, 'Caught exception on eval of elementList::filterQueryMultiValues() ' . $key . ': %s'); } if ($condition === 'NOT IN') { $partialComparison = ' NOT LIKE '; $comparison = ' <> '; $glue = ' AND '; } else { $partialComparison = ' LIKE '; $comparison = ' = '; $glue = ' OR '; } switch ($condition) { case 'IN': case 'NOT IN': /** * Split out 1,2,3 into an array to iterate over. * It's a string if pre-filter, array if element filter */ if (!is_array($originalValue)) { $originalValue = explode(',', $originalValue); } foreach ($originalValue as &$v) { $v = trim($v); $v = FabrikString::ltrimword($v, '"'); $v = FabrikString::ltrimword($v, "'"); $v = FabrikString::rtrimword($v, '"'); $v = FabrikString::rtrimword($v, "'"); } break; default: $originalValue = (array) $originalValue; break; } foreach ($originalValue as $v2) { $v2 = str_replace("/", "\\\\/", $v2); $str[] = '(' . $key . $partialComparison . $this->_db->q('%"' . $v2 . '"%') . $glue . $key . $comparison . $this->_db->q($v2) . ') '; } return '(' . implode($glue, $str) . ')'; }
/** * Get the js code to create the legend * * @return string */ function getLegend() { $db = FabrikWorker::getDbo(); $params = $this->getParams(); $this->setupEvents(); $tables = (array) $params->get('calendar_table'); $colour = (array) $params->get('colour'); $legend = (array) $params->get('legendtext'); $calendar = $this->_row; $ref = $this->getJSRenderContext(); // @TODO: json encode the returned value and move to the view $aLegend = "{$ref}.addLegend(["; $jsevents = array(); foreach ($this->_events as $listid => $record) { $listModel = JModel::getInstance('list', 'FabrikFEModel'); $listModel->setId($listid); $table = $listModel->getTable(); foreach ($record as $data) { $rubbish = $table->db_table_name . '___'; $colour = FabrikString::ltrimword($data['colour'], $rubbish); $legend = FabrikString::ltrimword($data['legendtext'], $rubbish); $label = empty($legend) ? $table->label : $legend; $aLegend .= "{'label':'" . $label . "','colour':'" . $colour . "'},"; } } $aLegend = rtrim($aLegend, ",") . "]);"; return $aLegend; }
/** * $$$tom : util function to turn the saved string into DMS coordinate array * @param string coordinates * @param int default zoom level * @return object coords array and zoomlevel int */ function _strToDMS($v) { $dms = new stdClass(); $dms->coords = array('', ''); if (strstr($v, ",")) { $ar = explode(":", $v); $v = FabrikString::ltrimword($ar[0], "("); $v = rtrim($v, ")"); $dms->coords = explode(",", $v); // Latitude if (strstr($dms->coords[0], '-')) { $dms_lat_dir = 'S'; } else { $dms_lat_dir = 'N'; } $dms_lat_deg = abs((int) $dms->coords[0]); $dms_lat_min_float = 60 * (abs($dms->coords[0]) - $dms_lat_deg); $dms_lat_min = (int) $dms_lat_min_float; $dms_lat_sec_float = 60 * ($dms_lat_min_float - $dms_lat_min); //Round the secs $dms_lat_sec = round($dms_lat_sec_float, 0); //$dms_lat_sec = $dms_lat_sec_float; if ($dms_lat_sec == 60) { $dms_lat_min += 1; $dms_lat_sec = 0; } if ($dms_lat_min == 60) { $dms_lat_deg += 1; $dms_lat_min = 0; } //@TODO $$$tom Maybe add the possibility to "construct" our own format: // W87°43'41" // W 87° 43' 41" (with the spacing) // 87°43'41" W (Direction at the end) // etc. // // Also: for the seconds: use 1 quote (") or 2 single quotes ('') ? Right now: 1 quote // Currently W87°43'41" $dms->coords[0] = $dms_lat_dir . $dms_lat_deg . '°' . $dms_lat_min . '’' . $dms_lat_sec . '"'; // Longitude if (strstr($dms->coords[1], '-')) { $dms_long_dir = 'W'; } else { $dms_long_dir = 'E'; } $dms_long_deg = abs((int) $dms->coords[1]); $dms_long_min_float = 60 * (abs($dms->coords[1]) - $dms_long_deg); $dms_long_min = (int) $dms_long_min_float; $dms_long_sec_float = 60 * ($dms_long_min_float - $dms_long_min); //Round the secs $dms_long_sec = round($dms_long_sec_float, 0); //$dms_long_sec = $dms_long_sec_float; if ($dms_long_sec == 60) { $dms_long_min += 1; $dms_long_sec = 0; } if ($dms_long_min == 60) { $dms_long_deg += 1; $dms_long_min = 0; } $dms->coords[1] = $dms_long_dir . $dms_long_deg . '°' . $dms_long_min . '’' . $dms_long_sec . '"'; } else { $dms->coords = array(0, 0); } return $dms; }
/** * Create the where part for the query that selects the list options * * @param array $data Current row data to use in placeholder replacements * @param bool $incWhere Should the additional user defined WHERE statement be included * @param string $thisTableAlias Db table alias * @param array $opts Options * @param bool|JDatabaseQuery $query Append where to JDatabaseQuery object or return string (false) * * @return string|JDatabaseQuery */ protected function buildQueryWhere($data = array(), $incWhere = true, $thisTableAlias = null, $opts = array(), $query = false) { $params = $this->getParams(); $element = $this->getElement(); $whereAccess = $params->get('database_join_where_access', 26); $where = $this->mustApplyWhere($whereAccess, $element->id) && $incWhere ? $params->get('database_join_where_sql') : ''; $join = $this->getJoin(); $thisTableAlias = is_null($thisTableAlias) ? $join->table_join_alias : $thisTableAlias; // $$$rob 11/10/2011 remove order by statements which will be re-inserted at the end of buildQuery() if (preg_match('/(ORDER\\s+BY)(.*)/i', $where, $matches)) { $this->orderBy = $this->parseThisTable($matches[0], $join); $where = str_replace($this->orderBy, '', $where); $where = str_replace($matches[0], '', $where); } if (!empty($this->autocomplete_where)) { $mode = FArrayHelper::getValue($opts, 'mode', 'form'); $displayType = $params->get('database_join_display_type', 'dropdown'); $filterType = $element->filter_type; if ($mode == 'filter' && $filterType == 'auto-complete' || $mode == 'form' && $displayType == 'auto-complete' || $mode == 'filter' && $displayType == 'auto-complete') { $where .= JString::stristr($where, 'WHERE') ? ' AND ' . $this->autocomplete_where : ' WHERE ' . $this->autocomplete_where; } } /* * $$$ hugh - experimenting with optional "filter where", will probably move this in to filterValueList_foo, * but first cut it's safer to put it here (don't ask). */ $filterWhere = trim($params->get('database_join_filter_where_sql', '')); if (FArrayHelper::getValue($opts, 'mode', '') === 'filter' && !empty($filterWhere)) { $where .= JString::stristr($where, 'WHERE') ? ' AND ' . $filterWhere : ' WHERE ' . $filterWhere; } if ($where == '') { return $query ? $query : $where; } $where = $this->parseThisTable($where, $join, $thisTableAlias); $w = new FabrikWorker(); $data = is_array($data) ? $data : array(); if (!isset($data['lang'])) { $data['lang'] = $this->lang->getTag(); } $where = $w->parseMessageForPlaceHolder($where, $data, false); if (!$query) { return $where; } else { $where = FabrikString::ltrimword($where, 'WHERE', true); $query->where($where); return $query; } }
/** * Build the filter query for the given element. * Can be overwritten in plugin - e.g. see checkbox element which checks for partial matches * * @param string $key Element name in format `tablename`.`elementname` * @param string $condition =/like etc. * @param string $value Search string - already quoted if specified in filter array options * @param string $originalValue Original filter value without quotes or %'s applied * @param string $type Filter type advanced/normal/prefilter/search/querystring/searchall * * @return string sql query part e,g, "key = value" */ public function getFilterQuery($key, $condition, $value, $originalValue, $type = 'normal') { $element = $this->getElement(); $db = JFactory::getDbo(); $condition = JString::strtoupper($condition); $this->encryptFieldName($key); $glue = 'OR'; if ($element->filter_type == 'checkbox' || $element->filter_type == 'multiselect') { $str = array(); if ($condition === 'NOT IN') { $partialComparison = ' NOT LIKE '; $comparison = ' <> '; $glue = ' AND '; } else { $partialComparison = ' LIKE '; $comparison = ' = '; $glue = ' OR '; } switch ($condition) { case 'IN': case 'NOT IN': /** * Split out 1,2,3 into an array to iterate over. * It's a string if pre-filter, array if element filter */ if (!is_array($originalValue)) { $originalValue = explode(',', $originalValue); } foreach ($originalValue as &$v) { $v = trim($v); $v = FabrikString::ltrimword($v, '"'); $v = FabrikString::ltrimword($v, "'"); $v = FabrikString::rtrimword($v, '"'); $v = FabrikString::rtrimword($v, "'"); } break; default: $originalValue = (array) $originalValue; break; } foreach ($originalValue as $v2) { $v2 = str_replace("/", "\\\\/", $v2); $str[] = '(' . $key . $partialComparison . $db->quote('%"' . $v2 . '"%') . $glue . $key . $comparison . $db->quote($v2) . ') '; } $str = '(' . implode($glue, $str) . ')'; } else { $originalValue = trim($value, "'"); /* * JSON stored values will back slash "/". So we need to add "\\\\" * before it to escape it for the query. */ $originalValue = str_replace("/", "\\\\/", $originalValue); if (strtoupper($condition) === 'IS NULL') { $value = ''; } switch ($condition) { case '=': case '<>': $condition2 = $condition == '=' ? 'LIKE' : 'NOT LIKE'; $glue = $condition == '=' ? 'OR' : 'AND'; $db = FabrikWorker::getDbo(); $str = "({$key} {$condition} {$value} " . " {$glue} {$key} {$condition2} " . $db->quote('["' . $originalValue . '"%') . " {$glue} {$key} {$condition2} " . $db->quote('%"' . $originalValue . '"%') . " {$glue} {$key} {$condition2} " . $db->quote('%"' . $originalValue . '"]') . ")"; break; default: $str = " {$key} {$condition} {$value} "; break; } } return $str; }
/** * Util function to turn the saved string into DMS coordinate array * * @param string $v Coordinates * * @return object Coords array and zoomlevel int */ protected function _strToDMS($v) { $dms = new stdClass(); $dms->coords = array('', ''); if (strstr($v, ",")) { $ar = explode(":", $v); $v = FabrikString::ltrimword($ar[0], "("); $v = rtrim($v, ")"); $dms->coords = explode(",", $v); // Latitude if (strstr($dms->coords[0], '-')) { $dms_lat_dir = 'S'; } else { $dms_lat_dir = 'N'; } $dms_lat_deg = abs((int) $dms->coords[0]); $dms_lat_min_float = 60 * (abs($dms->coords[0]) - $dms_lat_deg); $dms_lat_min = (int) $dms_lat_min_float; $dms_lat_sec_float = 60 * ($dms_lat_min_float - $dms_lat_min); // Round the secs $dms_lat_sec = round($dms_lat_sec_float, 0); if ($dms_lat_sec == 60) { $dms_lat_min++; $dms_lat_sec = 0; } if ($dms_lat_min == 60) { $dms_lat_deg++; $dms_lat_min = 0; } $dms->coords[0] = $dms_lat_dir . $dms_lat_deg . '°' . $dms_lat_min . '’' . $dms_lat_sec . '"'; // Longitude if (strstr($dms->coords[1], '-')) { $dms_long_dir = 'W'; } else { $dms_long_dir = 'E'; } $dms_long_deg = abs((int) $dms->coords[1]); $dms_long_min_float = 60 * (abs($dms->coords[1]) - $dms_long_deg); $dms_long_min = (int) $dms_long_min_float; $dms_long_sec_float = 60 * ($dms_long_min_float - $dms_long_min); // Round the secs $dms_long_sec = round($dms_long_sec_float, 0); if ($dms_long_sec == 60) { $dms_long_min++; $dms_long_sec = 0; } if ($dms_long_min == 60) { $dms_long_deg++; $dms_long_min = 0; } $dms->coords[1] = $dms_long_dir . $dms_long_deg . '°' . $dms_long_min . '’' . $dms_long_sec . '"'; } else { $dms->coords = array(0, 0); } return $dms; }
/** * Get base tag url * * @param string $fullName Full name (key value to remove from querystring) * @param string $rootUrl Optional root to use rather than REQUEST_URI * * @return string */ public static function tagBaseUrl($fullName, $rootUrl = null) { $url = filter_var(ArrayHelper::getValue($_SERVER, 'REQUEST_URI', 'index.php'), FILTER_SANITIZE_URL); $bits = explode('?', $url); $root = isset($rootUrl) ? $rootUrl : FArrayHelper::getValue($bits, 0, '', 'string'); $bits = FArrayHelper::getValue($bits, 1, '', 'string'); $bits = explode("&", $bits); for ($b = count($bits) - 1; $b >= 0; $b--) { $parts = explode("=", $bits[$b]); if (count($parts) > 1) { $key = FabrikString::ltrimword(FabrikString::safeColNameToArrayKey($parts[0]), '&'); if ($key == $fullName) { unset($bits[$b]); } if ($key == $fullName . '[value]') { unset($bits[$b]); } if ($key == $fullName . '[condition]') { unset($bits[$b]); } } } $url = $root . '?' . implode('&', $bits); return $url; }
/** * Get lists group by headings * * @return array heading names */ public function getGroupByHeadings() { $app = JFactory::getApplication(); $input = $app->input; $base = JURI::getInstance(); $base = $base->toString(array('scheme', 'user', 'pass', 'host', 'port', 'path')); $qs = $input->server->get('QUERY_STRING', '', 'string'); if (JString::stristr($qs, 'group_by')) { $qs = FabrikString::removeQSVar($qs, 'group_by'); $qs = FabrikString::ltrimword($qs, '?'); $qs = str_replace('&', '&', $qs); } $url = $base; if (!empty($qs)) { $url .= JString::strpos($url, '?') !== false ? '&' : '?'; $url .= $qs; } $url .= JString::strpos($url, '?') !== false ? '&' : '?'; $a = array(); list($h, $x, $b, $c) = $this->getHeadings(); $o = new stdClass(); $o->label = JText::_('COM_FABRIK_NONE'); $o->group_by = ''; $a[$url . 'group_by=0'] = $o; foreach ($h as $key => $v) { if (!in_array($key, array('fabrik_select', 'fabrik_edit', 'fabrik_view', 'fabrik_delete', 'fabrik_actions'))) { $thisurl = $url . 'group_by=' . $key; $o = new stdClass(); $o->label = strip_tags($v); $o->group_by = $key; $a[$thisurl] = $o; } } return $a; }