Ejemplo n.º 1
0
 /**
  * Get the map icons
  *
  * @return  array
  */
 public function getJSIcons()
 {
     $app = JFactory::getApplication();
     $input = $app->input;
     $icons = array();
     $w = new FabrikWorker();
     $uri = JURI::getInstance();
     $params = $this->getParams();
     $templates = (array) $params->get('fb_gm_detailtemplate');
     $templates_nl2br = (array) $params->get('fb_gm_detailtemplate_nl2br');
     $listids = (array) $params->get('googlemap_table');
     // Images for file system
     $aIconImgs = (array) $params->get('fb_gm_iconimage');
     // Image from marker data
     $markerImages = (array) $params->get('fb_gm_iconimage2');
     // Specified letter
     $letters = (array) $params->get('fb_gm_icon_letter');
     $aFirstIcons = (array) $params->get('fb_gm_first_iconimage');
     $aLastIcons = (array) $params->get('fb_gm_last_iconimage');
     $titleElements = (array) $params->get('fb_gm_title_element');
     $radiusElements = (array) $params->get('fb_gm_radius_element');
     $radiusDefaults = (array) $params->get('fb_gm_radius_default');
     $radiusUnits = (array) $params->get('fb_gm_radius_unit');
     $groupClass = (array) $params->get('fb_gm_group_class');
     $c = 0;
     $this->recordCount = 0;
     $maxMarkers = $params->get('fb_gm_markermax', 0);
     $recLimit = count($listids) == 1 ? $maxMarkers : 0;
     $limitMessageShown = false;
     $limitMessage = $params->get('fb_gm_markermax_message');
     $groupedIcons = array();
     $lc = 0;
     foreach ($listids as $listid) {
         $listModel = $this->getlistModel($listid);
         $template = JArrayHelper::getValue($templates, $c, '');
         /**
          * One day we should get smarter about how we decide which elements to render
          * but for now all we can do is set formatAll(), in case they use an element
          * which isn't set for list display, which then wouldn't get rendered unless we do this.
          */
         if (FabrikString::usesElementPlaceholders($template)) {
             $listModel->formatAll(true);
         }
         $template_nl2br = JArrayHelper::getValue($templates_nl2br, $c, '1') == '1';
         $table = $listModel->getTable();
         $mapsElements = FabrikHelperList::getElements($listModel, array('plugin' => 'googlemap', 'published' => 1));
         $coordColumn = $mapsElements[0]->getFullName(true, false) . "_raw";
         // Are we using random start location for icons?
         $listModel->_randomRecords = $params->get('fb_gm_random_marker') == 1 && $recLimit != 0 ? true : false;
         // Used in list model setLimits
         $input->set('limit' . $listid, $recLimit);
         $listModel->setLimits();
         $nav = $listModel->getPagination(0, 0, $recLimit);
         $data = $listModel->getData();
         $this->txt = array();
         $k = 0;
         foreach ($data as $groupKey => $group) {
             foreach ($group as $row) {
                 $customimagefound = false;
                 $iconImg = JArrayHelper::getValue($aIconImgs, $c, '');
                 if ($k == 0) {
                     $firstIcon = JArrayHelper::getValue($aFirstIcons, $c, $iconImg);
                     if ($firstIcon !== '') {
                         $iconImg = $firstIcon;
                     }
                 }
                 $v = $this->getCordsFromData($row->{$coordColumn});
                 if ($v == array(0, 0)) {
                     // Don't show icons with no data
                     continue;
                 }
                 $rowdata = JArrayHelper::fromObject($row);
                 $rowdata['rowid'] = $rowdata['__pk_val'];
                 $html = $w->parseMessageForPlaceHolder($template, $rowdata);
                 $titleElement = JArrayHelper::getValue($titleElements, $c, '');
                 $title = $titleElement == '' ? '' : strip_tags($row->{$titleElement});
                 /* $$$ hugh - if they provided a template, lets assume they will handle the link themselves.
                  * http://fabrikar.com/forums/showthread.php?p=41550#post41550
                  * $$$ hugh - at some point the fabrik_view / fabrik_edit links became optional
                  */
                 if (empty($html) && (array_key_exists('fabrik_view', $rowdata) || array_key_exists('fabrik_edit', $rowdata))) {
                     // Don't insert line break in empty bubble without links $html .= "<br />";
                     // Use edit link by preference
                     if (array_key_exists('fabrik_edit', $rowdata)) {
                         if ($rowdata['fabrik_edit'] != '') {
                             $html .= "<br />";
                         }
                         $html .= $rowdata['fabrik_edit'];
                     } else {
                         if ($rowdata['fabrik_view'] != '') {
                             $html .= "<br />";
                         }
                         $html .= $rowdata['fabrik_view'];
                     }
                 }
                 if ($template_nl2br) {
                     /*
                      *  $$$ hugh - not sure why we were doing this rather than nl2br?
                      If there was a reason, this is still broken, as it ends up inserting
                      two breaks.  So if we can't use nl2br ... I need fix this before using it again!
                     
                     $html = str_replace(array("\n\r"), "<br />", $html);
                     $html = str_replace(array("\r\n"), "<br />", $html);
                     $html = str_replace(array("\n", "\r"), "<br />", $html);
                     */
                     $html = nl2br($html);
                 }
                 $html = str_replace("'", '"', $html);
                 $this->txt[] = $html;
                 if ($iconImg == '') {
                     $iconImg = JArrayHelper::getValue($markerImages, $c, '');
                     if ($iconImg != '') {
                         $iconImg = JArrayHelper::getValue($rowdata, $iconImg, '');
                         // Get the src
                         preg_match('/src=["|\'](.*?)["|\']/', $iconImg, $matches);
                         if (array_key_exists(1, $matches)) {
                             $iconImg = $matches[1];
                             // Check file exists
                             $path = str_replace(COM_FABRIK_LIVESITE, '', $iconImg);
                             if (JFile::exists(JPATH_BASE . $path)) {
                                 $customimagefound = true;
                             }
                         }
                     }
                     if ($iconImg != '') {
                         list($width, $height) = $this->markerSize($iconImg);
                     } else {
                         // Standard google map icon size
                         $width = 20;
                         $height = 34;
                     }
                 } else {
                     // Standard google map icon size
                     list($width, $height) = $this->markerSize(JPATH_SITE . '/images/stories/' . $iconImg);
                 }
                 $gClass = JArrayHelper::getValue($groupClass, 0, '');
                 if (!empty($gClass)) {
                     $gClass .= '_raw';
                     $gClass = isset($row->{$gClass}) ? $row->{$gClass} : '';
                 }
                 if (array_key_exists($v[0] . $v[1], $icons)) {
                     $existingIcon = $icons[$v[0] . $v[1]];
                     if ($existingIcon['groupkey'] == $groupKey) {
                         /* $$$ hugh - this inserts label between multiple record $html, but not at the top.
                          * If they want to insert label, they can do it themselves in the template.
                          * $icons[$v[0].$v[1]][2] = $icons[$v[0].$v[1]][2] . "<h6>$table->label</h6>" . $html;
                          * Don't insert linebreaks in empty bubble
                          */
                         if ($html != '') {
                             $html = "<br />" . $html;
                         }
                         $icons[$v[0] . $v[1]][2] = $icons[$v[0] . $v[1]][2] . $html;
                         if ($customimagefound) {
                             $icons[$v[0] . $v[1]][3] = $iconImg;
                         }
                     } else {
                         $groupedIcons[] = array($v[0], $v[1], $html, $iconImg, $width, $height, 'groupkey' => $groupKey, 'listid' => $listid, 'title' => $title, 'groupClass' => 'type' . $gClass);
                     }
                 } else {
                     // Default icon - lets see if we need to use a letter icon instead
                     if (JArrayHelper::getValue($letters, $c, '') != '') {
                         $iconImg = $uri->getScheme() . '://www.google.com/mapfiles/marker' . JString::strtoupper($letters[$c]) . '.png';
                     }
                     $icons[$v[0] . $v[1]] = array($v[0], $v[1], $html, $iconImg, $width, $height, 'groupkey' => $groupKey, 'listid' => $listid, 'title' => $title, 'groupClass' => 'type' . $gClass);
                 }
                 if ($params->get('fb_gm_use_radius', '0') == '1') {
                     $radiusElement = JArrayHelper::getValue($radiusElements, $c, '');
                     $radiusUnits = JArrayHelper::getValue($radiusUnits, $c, 'k');
                     $radiusMeters = $radiusUnits == 'k' ? 1000 : 1609.34;
                     if (!empty($radiusElement)) {
                         $radius = (double) $row->{$radiusElement};
                         $radius *= $radiusMeters;
                         $icons[$v[0] . $v[1]]['radius'] = $radius;
                     } else {
                         $default = (double) JArrayHelper::getvalue($radiusDefaults, $c, 50);
                         $default *= $radiusMeters;
                         $icons[$v[0] . $v[1]]['radius'] = $default;
                     }
                 }
                 $icons[$v[0] . $v[1]]['c'] = $c;
                 $this->recordCount++;
                 $k++;
             }
         }
         // Replace last icon?
         $iconImg = JArrayHelper::getValue($aLastIcons, $c, '');
         if ($iconImg != '') {
             list($width, $height) = $this->markerSize(JPATH_SITE . '/media/com_fabrik/images/' . $iconImg);
             $icons[$v[0] . $v[1]][3] = $iconImg;
             $icons[$v[0] . $v[1]][4] = $width;
             $icons[$v[0] . $v[1]][5] = $height;
         }
         $c++;
     }
     // Replace coord keys with numeric keys
     $icons = array_values($icons);
     $icons = array_merge($icons, $groupedIcons);
     if ($maxMarkers != 0 && $maxMarkers < count($icons)) {
         $icons = array_slice($icons, -$maxMarkers);
     }
     $limitMessageShown = !($k >= $recLimit);
     if (!$limitMessageShown && $recLimit !== 0 && $limitMessage != '') {
         $app->enqueueMessage($limitMessage);
     }
     FabrikHelperHTML::debug($icons, 'map');
     return $icons;
 }
Ejemplo n.º 2
0
 /**
  * Get the map icons
  *
  * @return  array
  */
 public function getJSIcons()
 {
     $icons = array();
     $w = new FabrikWorker();
     $uri = JURI::getInstance();
     $params = $this->getParams();
     $templates = (array) $params->get('fb_gm_detailtemplate');
     $listids = (array) $params->get('googlemap_table');
     // Images for file system
     $aIconImgs = (array) $params->get('fb_gm_iconimage');
     // Image from marker data
     $markerImages = (array) $params->get('fb_gm_iconimage2');
     // Specifed letter
     $letters = (array) $params->get('fb_gm_icon_letter');
     $aFirstIcons = (array) $params->get('fb_gm_first_iconimage');
     $aLastIcons = (array) $params->get('fb_gm_last_iconimage');
     $titleElements = (array) $params->get('fb_gm_title_element');
     $groupClass = (array) $params->get('fb_gm_group_class');
     $c = 0;
     $this->recordCount = 0;
     $maxMarkers = $params->get('fb_gm_markermax', 0);
     $recLimit = count($listids) == 1 ? $maxMarkers : 0;
     $limitMessageShown = false;
     $limitMessage = $params->get('fb_gm_markermax_message');
     $groupedIcons = array();
     $k = 0;
     foreach ($listids as $listid) {
         $template = JArrayHelper::getValue($templates, $c, '');
         $listModel = $this->getlistModel($listid);
         $table = $listModel->getTable();
         try {
             $mapsElements = FabrikHelperList::getElements($listModel, array('plugin' => 'googlemap', 'published' => 1));
         } catch (Exception $e) {
             JError::raiseError(500, $e->getMessage());
         }
         $coordColumn = $mapsElements[0]->getFullName(false, true, false) . "_raw";
         // Are we using random start location for icons?
         $listModel->_randomRecords = $params->get('fb_gm_random_marker') == 1 && $recLimit != 0 ? true : false;
         // Used in table model setLimits
         JRequest::setVar('limit' . $listid, $recLimit);
         $listModel->setLimits();
         $nav = $listModel->getPagination(0, 0, $recLimit);
         $data = $listModel->getData();
         $this->txt = array();
         $k = 0;
         foreach ($data as $groupKey => $group) {
             foreach ($group as $row) {
                 $customimagefound = false;
                 $iconImg = JArrayHelper::getValue($aIconImgs, $c, '');
                 if ($k == 0) {
                     $firstIcon = JArrayHelper::getValue($aFirstIcons, $c, $iconImg);
                     if ($firstIcon !== '') {
                         $iconImg = $firstIcon;
                     }
                 }
                 $v = $this->getCordsFromData($row->{$coordColumn});
                 if ($v == array(0, 0)) {
                     // Don't show icons with no data
                     continue;
                 }
                 $rowdata = JArrayHelper::fromObject($row);
                 $rowdata['rowid'] = $rowdata['__pk_val'];
                 $html = $w->parseMessageForPlaceHolder($template, $rowdata);
                 $titleElement = JArrayHelper::getValue($titleElements, $c, '');
                 $title = $titleElement == '' ? '' : strip_tags($row->{$titleElement});
                 /* $$$ hugh - if they provided a template, lets assume they will handle the link themselves.
                  * http://fabrikar.com/forums/showthread.php?p=41550#post41550
                  * $$$ hugh - at some point the fabrik_view / fabrik_edit links became optional
                  */
                 if (empty($html) && (array_key_exists('fabrik_view', $rowdata) || array_key_exists('fabrik_edit', $rowdata))) {
                     $html .= "<br />";
                     // Use edit link by preference
                     if (array_key_exists('fabrik_edit', $rowdata)) {
                         $html .= $rowdata['fabrik_edit'];
                     } else {
                         $html .= $rowdata['fabrik_view'];
                     }
                 }
                 $html = str_replace(array("\n\r"), "<br />", $html);
                 $html = str_replace(array("\n", "\r"), "<br />", $html);
                 $html = str_replace("'", '"', $html);
                 $this->txt[] = $html;
                 if ($iconImg == '') {
                     $iconImg = JArrayHelper::getValue($markerImages, $c, '');
                     if ($iconImg != '') {
                         $iconImg = JArrayHelper::getValue($rowdata, $iconImg, '');
                         // Get the src
                         preg_match('/src=["|\'](.*?)["|\']/', $iconImg, $matches);
                         if (array_key_exists(1, $matches)) {
                             $iconImg = $matches[1];
                             // Check file exists
                             $path = str_replace(COM_FABRIK_LIVESITE, '', $iconImg);
                             if (JFile::exists(JPATH_BASE . $path)) {
                                 $customimagefound = true;
                             }
                         }
                     }
                     if ($iconImg != '') {
                         list($width, $height) = $this->markerSize($iconImg);
                     } else {
                         // Standard google map icon size
                         $width = 20;
                         $height = 34;
                     }
                 } else {
                     // Standard google map icon size
                     list($width, $height) = $this->markerSize(JPATH_SITE . '/images/stories/' . $iconImg);
                 }
                 // Just for moosehunt!
                 $radomize = $_SERVER['HTTP_HOST'] == 'moosehunt.mobi' ? true : false;
                 $groupKey = strip_tags($groupKey);
                 $gClass = JArrayHelper::getValue($groupClass, 0, '');
                 if (!empty($gClass)) {
                     $gClass .= '_raw';
                     $gClass = isset($row->{$gClass}) ? $row->{$gClass} : '';
                 }
                 if (array_key_exists($v[0] . $v[1], $icons)) {
                     $existingIcon = $icons[$v[0] . $v[1]];
                     if ($existingIcon['groupkey'] == $groupKey) {
                         /* $$$ hugh - this inserts label between multiple record $html, but not at the top.
                          * If they want to insert label, they can do it themselves in the template.
                          * $icons[$v[0].$v[1]][2] = $icons[$v[0].$v[1]][2] . "<h6>$table->label</h6>" . $html;
                          */
                         $icons[$v[0] . $v[1]][2] = $icons[$v[0] . $v[1]][2] . "<br />" . $html;
                         if ($customimagefound) {
                             $icons[$v[0] . $v[1]][3] = $iconImg;
                         }
                     } else {
                         $groupedIcons[] = array($v[0], $v[1], $html, $iconImg, $width, $height, 'groupkey' => $groupKey, 'listid' => $listid, 'title' => $title, 'groupClass' => 'type' . $gClass);
                     }
                 } else {
                     // Default icon - lets see if we need to use a letterd icon instead
                     if (JArrayHelper::getValue($letters, $c, '') != '') {
                         $iconImg = $uri->getScheme() . '://www.google.com/mapfiles/marker' . JString::strtoupper($letters[$c]) . '.png';
                     }
                     $icons[$v[0] . $v[1]] = array($v[0], $v[1], $html, $iconImg, $width, $height, 'groupkey' => $groupKey, 'listid' => $listid, 'title' => $title, 'groupClass' => 'type' . $gClass);
                 }
                 $this->recordCount++;
                 $k++;
             }
         }
         // Replace last icon?
         $iconImg = JArrayHelper::getValue($aLastIcons, $c, '');
         if ($iconImg != '') {
             list($width, $height) = $this->markerSize(JPATH_SITE . '/media/com_fabrik/images/' . $iconImg);
             $icons[$v[0] . $v[1]][3] = $iconImg;
             $icons[$v[0] . $v[1]][4] = $width;
             $icons[$v[0] . $v[1]][5] = $height;
         }
         $c++;
     }
     // Replace coord keys with numeric keys
     $icons = array_values($icons);
     $icons = array_merge($icons, $groupedIcons);
     if ($maxMarkers != 0 && $maxMarkers < count($icons)) {
         $icons = array_slice($icons, -$maxMarkers);
     }
     $limitMessageShown = !($k >= $recLimit);
     if (!$limitMessageShown && $recLimit !== 0 && $limitMessage != '') {
         $app->enqueueMessage($limitMessage);
     }
     FabrikHelperHTML::debug($icons, 'map');
     return $icons;
 }