Exemple #1
0
 /**
  * Constructor.
  *
  * @param Registry $config    The config object.
  * @param string   $extension The extension name.
  */
 public function __construct(Registry $config = null, $extension = null)
 {
     $config = $config ?: new Registry();
     $this->extension = $extension;
     $this->resetCachePosition();
     $this->config->merge($config);
 }
 /**
  * Renders a module script and returns the results as a string
  *
  * @param   mixed   $module   The name of the module to render
  * @param   array   $attribs  Associative array of values
  * @param   string  $content  If present, module information from the buffer will be used
  *
  * @return  string  The output of the script
  *
  * @since   11.1
  */
 public function render($module, $attribs = array(), $content = null)
 {
     if (!is_object($module)) {
         $title = isset($attribs['title']) ? $attribs['title'] : null;
         $module = JModuleHelper::getModule($module, $title);
         if (!is_object($module)) {
             if (is_null($content)) {
                 return '';
             } else {
                 /**
                  * If module isn't found in the database but data has been pushed in the buffer
                  * we want to render it
                  */
                 $tmp = $module;
                 $module = new stdClass();
                 $module->params = null;
                 $module->module = $tmp;
                 $module->id = 0;
                 $module->user = 0;
             }
         }
     }
     // Get the user and configuration object
     // $user = JFactory::getUser();
     $conf = Factory::getConfig();
     // Set the module content
     if (!is_null($content)) {
         $module->content = $content;
     }
     // Get module parameters
     $params = new Registry();
     $params->loadString($module->params);
     // Use parameters from template
     if (isset($attribs['params'])) {
         $template_params = new Registry();
         $template_params->loadString(html_entity_decode($attribs['params'], ENT_COMPAT, 'UTF-8'));
         $params->merge($template_params);
         $module = clone $module;
         $module->params = (string) $params;
     }
     $contents = '';
     // Default for compatibility purposes. Set cachemode parameter or use JModuleHelper::moduleCache from within the
     // module instead
     $cachemode = $params->get('cachemode', 'oldstatic');
     if ($params->get('cache', 0) == 1 && $conf->get('caching') >= 1 && $cachemode != 'id' && $cachemode != 'safeuri') {
         // Default to itemid creating method and workarounds on
         $cacheparams = new stdClass();
         $cacheparams->cachemode = $cachemode;
         $cacheparams->class = 'JModuleHelper';
         $cacheparams->method = 'renderModule';
         $cacheparams->methodparams = array($module, $attribs);
         $contents = JModuleHelper::ModuleCache($module, $params, $cacheparams);
     } else {
         $contents = JModuleHelper::renderModule($module, $attribs);
     }
     return $contents;
 }
 /**
  * Get component params.
  *
  * @return  Registry
  */
 public function getParams()
 {
     if ($this->params) {
         return $this->params;
     }
     $app = $this->getContainer()->get('app');
     $comParams = ExtensionHelper::getParams($this->option);
     $menuParams = new Registry();
     if ($menu = $app->getMenu()->getActive()) {
         $menuParams->loadString($menu->params);
     }
     $menuParams->merge($comParams);
     return $this->params = $menuParams;
 }
Exemple #4
0
 protected function load()
 {
     //the cart is in the session, or in state.
     //We start with getting the cart items, then enumerating them to get each cart item type, so we can process
     //it through its plugin.
     $this->product = Sp4kAppsProductApp::getInstance(new Joomla\Registry\Registry(['id' => $this->getState()->get('product_id')]))->getItem();
     $config = $this->product->config;
     foreach (get_object_vars($config) as $index => $configopt) {
         $state = new Registry(['options' => $configopt]);
         $state->merge($this->getState());
         $cartPluginClassName = 'Sp4kAppsCartPlugins' . ucfirst($index) . 'Plg';
         if (class_exists($cartPluginClassName)) {
             $this->plugins[$index] = $cartPluginClassName::getInstance($state);
         }
     }
     //$this->plugins['summary'] = Sp4kAppsCartPluginsSummaryPlg::getInstance($this->getState());
     $this->cart_key = md5($this->getState()->get('event_id') . '.' . $this->getState()->get('product_id') . '.' . $this->getState()->get('child_id'));
     // set the state to the table data so
     // that any empty variables in the incoming data are populated with table data.
     //$this->getState()->loadArray(get_object_vars($this->_table),true);
 }
 /**
  * Constructor.
  *
  * @param string           $name        The Component name.
  * @param \JInput          $input       The Input object.
  * @param \JApplicationCms $application The Application object.
  * @param Container        $container   The DI container.
  *
  * @throws \Exception
  */
 public function __construct($name = null, $input = null, $application = null, $container = null)
 {
     $this->name = $name;
     // Guess component name.
     if (!$this->name) {
         $reflection = $this->getReflection();
         $this->name = $reflection->getShortName();
         $this->name = strtolower(str_replace('Component', '', $this->name));
         if (!$this->name) {
             throw new \Exception('Component need name.');
         }
     }
     $this->option = 'com_' . strtolower($this->name);
     $this->container = $container ?: Container::getInstance($this->option);
     $this->application = $application ?: $this->container->get('app');
     $this->input = $input ?: $this->application->input;
     // Add a config but make it B/C
     if ($this->container->exists($this->option . '.config')) {
         $this->config = $this->container->get($this->option . '.config');
     }
     $this->config = $this->config ?: new Registry();
     $this->config->merge(\JComponentHelper::getParams($this->option));
     $this->init();
 }
    /**
     * Test the Joomla\Registry\Registry::merge method.
     *
     * @return  void
     *
     * @covers  Joomla\Registry\Registry::merge
     * @since   1.0
     */
    public function testMerge()
    {
        $array1 = array('foo' => 'bar', 'hoo' => 'hum', 'dum' => array('dee' => 'dum'));
        $array2 = array('foo' => 'soap', 'dum' => 'huh');
        $registry1 = new Registry();
        $registry1->loadArray($array1);
        $registry2 = new Registry();
        $registry2->loadArray($array2);
        $registry1->merge($registry2);
        // Test getting a known value.
        $this->assertThat($registry1->get('foo'), $this->equalTo('soap'), 'Line: ' . __LINE__ . '.');
        $this->assertThat($registry1->get('dum'), $this->equalTo('huh'), 'Line: ' . __LINE__ . '.');
        // Test merge with zero and blank value
        $json1 = '{
			"param1":1,
			"param2":"value2"
		}';
        $json2 = '{
			"param1":2,
			"param2":"",
			"param3":0,
			"param4":-1,
			"param5":1
		}';
        $a = new Registry($json1);
        $b = new Registry();
        $b->loadString($json2, 'JSON');
        $result = $a->merge($b);
        // New param with zero value should show in merged registry
        $this->assertEquals(2, $a->get('param1'), '$b value should override $a value');
        $this->assertEquals('value2', $a->get('param2'), '$a value should override blank $b value');
        $this->assertEquals(0, $a->get('param3'), '$b value of 0 should override $a value');
        $this->assertEquals(-1, $a->get('param4'), '$b value of -1 should override $a value');
        $this->assertEquals(1, $a->get('param5'), '$b value of 1 should override $a value');
        // Test recursive merge
        $registry = new Registry();
        $object1 = '{
			"foo" : "foo value",
			"bar" : {
				"bar1" : "bar value 1",
				"bar2" : "bar value 2"
			}
		}';
        $object2 = '{
			"foo" : "foo value",
			"bar" : {
				"bar2" : "new bar value 2"
			}
		}';
        $registry1 = new Registry(json_decode($object1));
        $registry2 = new Registry(json_decode($object2));
        $registry1->merge($registry2, true);
        $this->assertEquals($registry1->get('bar.bar2'), 'new bar value 2', 'Line: ' . __LINE__ . '. bar.bar2 shuould be override.');
        $this->assertEquals($registry1->get('bar.bar1'), 'bar value 1', 'Line: ' . __LINE__ . '. bar.bar1 should not be overrided.');
        // Chicking we merge a non Registry object will return error.
        $a = new Registry();
        $b = new stdClass();
        try {
            $a->merge($b);
        } catch (Exception $e) {
            $this->assertInstanceOf('PHPUnit_Framework_Error', $e, 'Line: ' . __LINE__ . '. Attempt to merge non Registry should return Error');
        }
    }
Exemple #7
0
 /**
  * @testdox  Two Registry instances can be merged
  *
  * @covers   Joomla\Registry\Registry::merge
  */
 public function testANonRegistryObjectCannotBeMergedIntoARegistry()
 {
     $registry = new Registry();
     $this->assertFalse($registry->merge(new \stdClass()), 'Only Registry instances can be merged together.');
 }
	/**
	 * Display function
	 *
	 * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
	 *
	 * @return  mixed  A string if successful, otherwise a Error object.
	 *
	 * @since       1.7.2
	 */
	public function display ($tpl = null)
	{
		$renderHelper = new ChurchDirectoryRenderHelper;

		// Get some data from the models
		$state      = $this->get('State');
		/** @var Registry $params */
		$params     = $state->params;
		$items      = $this->get('Items');
		$category   = $this->get('Category');
		$children   = $this->get('Children');
		$parent     = $this->get('Parent');
		$pagination = $this->get('Pagination');

		// Check whether category access level allows access.
		$user   = JFactory::getUser();
		$groups = $user->getAuthorisedViewLevels();

		if (!in_array($category->access, $groups))
		{
			echo JText::_('JERROR_ALERTNOAUTHOR');

			return false;
		}

		if ($items == false || empty($items))
		{
			echo JText::_('COM_CHURCHDIRECTOY_ERROR_DIRECTORY_NOT_FOUND');

			return false;
		}

		// Prepare the data.
		for ($i = 0, $n = count($items); $i < $n; $i++)
		{
			$item = &$items[$i];

			// Compute the contact slug.
			$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;

			$item->event = new stdClass;
			$temp        = new Registry;
			$temp->loadString($item->params);
			$item->params = clone $params;
			$item->params->merge($temp);

			if ($item->params->get('dr_show_email', 0) == 1)
			{
				$item->email_to = trim($item->email_to);

				if (empty($item->email_to) && !JMailHelper::isEmailAddress($item->email_to))
				{
					$item->email_to = null;
				}
			}
		}

		// Setup the category parameters.
		$cparams          = $category->getParams();
		$category->params = clone $params;
		$category->params->merge($cparams);
		$children = [$category->id => $children];

		$maxLevel         = $params->get('maxLevel', -1);
		$this->maxLevel   = &$maxLevel;
		$this->state      = &$state;
		$this->items      = &$items;
		$this->category   = &$category;
		$this->children   = &$children;
		$this->params     = &$params;
		$this->parent     = &$parent;
		$this->pagination = &$pagination;

		// Creates an array of strings to hold the lines of the KML file.
		$kml   = ['<?xml version="1.0" encoding="UTF-8"?>'];
		$kml[] = '<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2"'
				. ' xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">';
		$kml[] = '<Document>';
		$kml[] = '<name>' . $items[0]->kml_name . '</name>';
		$kml[] = '<open>' . $items[0]->kml_params->get('open') . '</open>';
		$kml[] = '<LookAt>
    		 <longitude>' . $items[0]->kml_lng . '</longitude>
    		 <latitude>' . $items[0]->kml_lat . '</latitude>
		 <altitude>' . $items[0]->kml_params->get('altitude') . '</altitude>
		 <range>' . $items[0]->kml_params->get('range') . '</range>
		 <tilt>' . $items[0]->kml_params->get('tilt') . '</tilt>
		 <heading>' . $items[0]->kml_params->get('heading') . '</heading>
		 <gx:altitudeMode>' . $items[0]->kml_params->get('gxaltitudeMode') . '</gx:altitudeMode>
  	     </LookAt>    <!-- Camera or LookAt -->';
		$kml[] = $items[0]->kml_style;

		$kml[] = '<StyleMap id="text_photo_banner0">
		<Pair>
			<key>normal</key>
			<styleUrl>#text_photo_banner</styleUrl>
		</Pair>
		<Pair>
			<key>highlight</key>
			<styleUrl>#text_photo_banner1</styleUrl>
		</Pair>
	</StyleMap>';
		$kml[] = '<Style id="text_photo_banner">';
		$kml[] = '<IconStyle>';
		$kml[] = '<scale>';

		if ($items[0]->params->get('icscale') == null)
		{
			$kml[] = '1.1';
		}
		else
		{
			$kml[] = $items[0]->kml_params->get('icscale');
		}

		$kml[] = '</scale>';
		$kml[] = '<Icon>';
		$kml[] = '<href>';

		if ($items[0]->category_params->get('image') === null)
		{
			$kml[] = JUri::base() . 'media/com_churchdirectory/images/kml_icons/iconb.png';
		}
		else
		{
			$kml[] = JUri::base() . $items[0]->category_params->get('image');
		}

		$kml[] = '</href>';
		$kml[] = '</Icon>';
		$kml[] = '<hotSpot x="0.5" y="0.5" xunits="fraction" yunits="fraction"/>';
		$kml[] = '</IconStyle>';
		$kml[] = '<LabelStyle>';
		$kml[] = '<scale>';

		if ($items[0]->params->get('lsscale') == null)
		{
			$kml[] = '.6';
		}
		else
		{
			$kml[] = $items[0]->kml_params->get('lsscale');
		}

		$kml[] = '</scale>';
		$kml[] = '</LabelStyle>';
		$kml[] = '</Style> ';
		$kml[] = '<Style id="text_photo_banner1">';
		$kml[] = '<IconStyle>';
		$kml[] = '<scale>';

		if ($items[0]->params->get('icscale') == null)
		{
			$kml[] = '1.1';
		}
		else
		{
			$kml[] = $items[0]->kml_params->get('icscale');
		}

		$kml[] = '</scale>';
		$kml[] = '<Icon>';
		$kml[] = '<href>';

		if ($items[0]->category_params->get('image') === null)
		{
			$kml[] = JUri::base() . 'media/com_churchdirectory/images/kml_icons/iconb.png';
		}
		else
		{
			$kml[] = JUri::base() . $items[0]->category_params->get('image');
		}

		$kml[] = '</href>';
		$kml[] = '</Icon>';
		$kml[] = '<hotSpot x="0.5" y="0.5" xunits="fraction" yunits="fraction"/>';
		$kml[] = '</IconStyle>';
		$kml[] = '<LabelStyle>';
		$kml[] = '<scale>';

		if ($items[0]->params->get('lsscale') == null)
		{
			$kml[] = '.6';
		}
		else
		{
			$kml[] = $items[0]->kml_params->get('lsscale');
		}

		$kml[] = '</scale>';
		$kml[] = '</LabelStyle>';
		$kml[] = '</Style> ';
		$teams = $renderHelper->groupit(['items' => $items, 'field' => 'category_title']);
		$new_rows = [];
		$ckml_params = new Registry;

		foreach ($teams as $c => $catid)
		{
			$new_rows[$c] = $renderHelper->groupit(['items' => $teams[$c], 'field' => 'suburb']);
			$ckml_params->merge($catid[0]->kml_params);
		}

		$mycounter = '0';

		foreach ($new_rows as $c => $suburb)
		{
			$mycounter++;
			$kml[] = '<Folder id="' . $mycounter . '"> ';
			$kml[] = '<name>';
			$kml[] = $c;
			$kml[] = '</name>';
			$kml[] = '<open>' . $ckml_params->get('mcropen') . '</open>           <!-- boolean -->';

			foreach ($suburb as $s => $rows)
			{
				$mycounter++;
				$kml[] = ' <Folder id="' . $mycounter . '"> ';
				$kml[] = ' <name>' . $s . ' </name> ';
				$kml[] = ' <open>' . $ckml_params->get('msropen') . '</open>           	   <!-- boolean -->';

				foreach ($rows as $row)
				{
					$mycounter++;
					$kml[] = '<Placemark id="placemark' . $mycounter . ' "> ';
					$kml[] = '<name>' . $row->name . '</name>';
					$kml[] = '<visibility>';

					if ($row->params->get('visibility') == null)
					{
						$kml[] = '0';
					}
					else
					{
						$kml[] = $row->params->get('visibility');
					}

					$kml[] = '</visibility><open>';

					if ($row->params->get('open') == null)
					{
						$kml[] = '0';
					}
					else
					{
						$kml[] = $row->params->get('open');
					}

					$kml[] = '</open>';
					$kml[] = '<gx:balloonVisibility>';

					if ($row->params->get('gxballoonvisibility') == null)
					{
						$kml[] = '0';
					}
					else
					{
						$kml[] = $row->params->get('gxballoonvisibility');
					}

					$kml[] = '</gx:balloonVisibility>';
					$kml[] = '<address><![CDATA[';

					if ($row->address != null)
					{
						$kml[] = $row->address . ',<br />';
					}

					$kml[] = $row->suburb . ', ' . $row->state . ' ' . $row->postcode;
					$kml[] = ']]></address> <!-- string -->';
					$kml[] = '<phoneNumber>' . $row->telephone . '</phoneNumber> <!-- string -->';
					$kml[] = '<Snippet maxLines="';

					if ($row->kml_params->get('rmaxlines') == null)
					{
						$kml[] = '2';
					}
					else
					{
						$kml[] = $row->kml_params->get('rmaxlines');
					}

					$kml[] = '">More coming soon</Snippet>   <!-- string -->';
					$kml[] = '<description>' . '<![CDATA[<div style="padding: 10px;">';

					if (empty($row->image))
					{
						$kml[] = '<img src="' . JUri::base() . 'media/com_churchdirectory/images/photo_not_available.jpg" alt="Photo" width="100" hight="100" /><br />';
					}
					else
					{
						$kml[] = '<img src="' . JUri::base() . $row->image . '" alt="Photo" width="100" hight="100" /><br />';
					}

					if (!empty($row->id))
					{
						$kml[] = '<b>Position:</b> Fixing sitll need to implement<br />';
					}

					if (!empty($row->spouse))
					{
						$kml[] = 'Spouse: ' . $row->spouse . '<br />';
					}

					if (!empty($row->children))
					{
						$kml[] = 'Children: ' . $row->children . '<br />';
					}

					if (!empty($row->misc))
					{
						$kml[] = $row->misc;
					}

					if (!empty($row->telephone))
					{
						$kml[] = '<br />PH: ' . $row->telephone;
					}

					if (!empty($row->fax))
					{
						$kml[] = '<br />Fax: ' . $row->fax;
					}

					if (!empty($row->mobile))
					{
						$kml[] = '<br />Cell: ' . $row->mobile;
					}

					if (!empty($row->email_to))
					{
						$kml[] = '<br />Email: <a href="mailto:' . $row->email_to . '">' . $row->email_to . '</a>';
					}

					$kml[] = '</div>]]>' . '</description>';
					$kml[] = '<styleUrl>#text_photo_banner0</styleUrl>';
					$kml[] = '<Point>';
					$kml[] = '<coordinates>' . $row->lng . ',' . $row->lat . ',0</coordinates>';
					$kml[] = '</Point>';
					$kml[] = '</Placemark>';
				} /* End the state folder */
				$kml[] = '</Folder>';
			} /* End the country folder */
			$kml[] = '</Folder>';
		}

		header('Content-type: application/vnd.google-earth.kml+xml');
		header('Content-disposition: attachment; filename="' . $items[0]->kml_alias . '.kml"');

		// End KML file
		$kml[]     = '</Document>';
		$kml[]     = '</kml>';
		$kmlOutput = join("\n", $kml);
		echo $kmlOutput;

		return true;
	}