Пример #1
0
 public function getDynamicValues($id, $view)
 {
     // Get a db connection.
     $db = JFactory::getDbo();
     // Create a new query object.
     $query = $db->getQuery(true);
     $query->select($db->quoteName(array('getcustom', 'gettype', 'main_source', 'view_selection', 'db_selection', 'join_view_table', 'join_db_table', 'addcalculation', 'php_calculation')));
     $query->from($db->quoteName('#__componentbuilder_dynamic_get'));
     $query->where($db->quoteName('published') . ' = 1');
     $query->where($db->quoteName('id') . ' = ' . (int) $id);
     // Reset the query using our newly populated query object.
     $db->setQuery($query);
     $db->execute();
     if ($db->getNumRows()) {
         $result = $db->loadObject();
         // reset buket
         $selections = array();
         $selectionsList = array();
         // get the main values (name)
         if ($result->main_source == 1) {
             $selections[] = explode("\n", $result->view_selection);
         } elseif ($result->main_source == 2) {
             $selections[] = explode("\n", $result->db_selection);
         } elseif ($result->main_source == 3) {
             return '<br /><br /><h2>Custom get source! You will need to transpose the variables manually.</h2>';
         }
         // get the joined values (name)
         $join_view_table = json_decode($result->join_view_table, true);
         unset($result->join_view_table);
         if (ComponentbuilderHelper::checkArray($join_view_table)) {
             foreach ($join_view_table as $option => $values) {
                 foreach ($values as $nr => $value) {
                     $result->join_view_table[$nr][$option] = $value;
                 }
             }
         }
         unset($join_view_table);
         $join_db_table = json_decode($result->join_db_table, true);
         unset($result->join_db_table);
         if (ComponentbuilderHelper::checkArray($join_db_table)) {
             foreach ($join_db_table as $option => $values) {
                 foreach ($values as $nr => $value) {
                     $result->join_db_table[$nr][$option] = $value;
                 }
             }
         }
         unset($join_db_table);
         // now load the joined values to the selection set
         if (isset($result->join_view_table) && ComponentbuilderHelper::checkArray($result->join_view_table)) {
             foreach ($result->join_view_table as $join_view_table) {
                 if ($join_view_table['row_type'] == '1') {
                     $selections[] = explode("\n", $join_view_table['selection']);
                 } elseif ($join_view_table['row_type'] == '2') {
                     $names = $this->setListMethodName(array($join_view_table['on_field'], $join_view_table['join_field']), $join_view_table['view_table'], $join_view_table['as'], 1);
                     $selectionsList[implode('', $names)] = explode("\n", $join_view_table['selection']);
                 }
             }
             unset($result->join_view_table);
         }
         if (isset($result->join_db_table) && ComponentbuilderHelper::checkArray($result->join_db_table)) {
             foreach ($result->join_db_table as $join_db_table) {
                 if ($join_db_table['row_type'] == '1') {
                     $selections[] = explode("\n", $join_db_table['selection']);
                 } elseif ($join_db_table['row_type'] == '2') {
                     $names = $this->setListMethodName(array($join_db_table['on_field'], $join_db_table['join_field']), $join_db_table['db_table'], $join_db_table['as'], 2);
                     $selectionsList[implode('', $names)] = explode("\n", $join_db_table['selection']);
                 }
             }
             unset($result->join_db_table);
         }
         // get the calculation reult values (name)
         if ($result->addcalculation == 1) {
             $php_calculation = base64_decode($result->php_calculation);
             $phpSelections = ComponentbuilderHelper::getAllBetween($php_calculation, 'cal__', ' ');
             $selections[] = array_unique($phpSelections);
             unset($php_calculation);
             unset($phpSelections);
             unset($result->php_calculation);
         }
         // name the main var based on view
         if ($view == 'template') {
             switch ($result->gettype) {
                 case 1:
                     // single
                     $buketName = 'this->item';
                     break;
                 case 2:
                     // list
                     $buketName = 'this->items';
                     break;
                 case 3:
                 case 4:
                     // custom
                     $result->getcustom = ComponentbuilderHelper::safeString($result->getcustom);
                     if (substr($result->getcustom, 0, strlen('get')) == 'get') {
                         $varName = substr($result->getcustom, strlen('get'));
                     } else {
                         $varName = $result->getcustom;
                     }
                     $buketName = 'this->' . $varName;
                     break;
             }
         } elseif ($view == 'layout') {
             $buketName = 'displayData';
         }
         // now build the return values
         if (ComponentbuilderHelper::checkArray($selections)) {
             $buket = array();
             switch ($result->gettype) {
                 case 1:
                 case 3:
                     // single
                     $ur = '&lt;?php echo $' . $buketName;
                     $cf = '; ?&gt;';
                     break;
                 case 2:
                 case 4:
                     // list
                     $ur = '&lt;?php echo $item';
                     $cf = '; ?&gt;';
                     $buket[] = '<code>&lt;?php foreach ($' . $buketName . ' as $item): ?&gt;</code><br />';
                     break;
             }
             foreach ($selections as $selection) {
                 if (ComponentbuilderHelper::checkArray($selection)) {
                     foreach ($selection as $value) {
                         if (strpos($value, 'AS') !== false) {
                             list($table, $key) = explode('AS', $value);
                             $buket[] = '<code>' . $ur . '->' . trim($key) . $cf . '</code>';
                         } else {
                             $buket[] = '<code>' . $ur . '->' . trim($value) . $cf . '</code>';
                         }
                     }
                 }
             }
             if (ComponentbuilderHelper::checkArray($selectionsList)) {
                 $buket[] = '<hr />';
                 foreach ($selectionsList as $name => $selectionList) {
                     if (ComponentbuilderHelper::checkArray($selectionList)) {
                         $ur = '&lt;?php echo $' . $name;
                         $cf = '; ?&gt;';
                         $buket[] = '<code>&lt;?php foreach ($item->' . $name . ' as $' . $name . '): ?&gt;</code><br />';
                         foreach ($selectionList as $value) {
                             if (strpos($value, 'AS') !== false) {
                                 list($table, $key) = explode('AS', $value);
                                 $buket[] = '<code>' . $ur . '->' . trim($key) . $cf . '</code>';
                             } else {
                                 $buket[] = '<code>' . $ur . '->' . trim($value) . $cf . '</code>';
                             }
                         }
                         $buket[] = '<br /><code>&lt;?php endforeach; ?&gt;</code><hr />';
                     }
                 }
             }
             switch ($result->gettype) {
                 case 2:
                 case 4:
                     // list
                     $buket[] = '<br /><code>&lt;?php endforeach; ?&gt;</code>';
                     break;
             }
             return implode('&nbsp;', $buket);
         }
     }
     return false;
 }
 public function setDashboardModelMethods()
 {
     if ($this->componentData->add_php_dashboard_methods) {
         // get all the mothods that should load date to the view
         $this->DashboardGetCustomData = ComponentbuilderHelper::getAllBetween($this->componentData->php_dashboard_methods, 'public function get', '()');
         // return the methods
         return "\n\n" . str_replace(array_keys($this->placeholders), array_values($this->placeholders), $this->componentData->php_dashboard_methods);
     }
     return '';
 }
Пример #3
0
 /**
  * Set Custom Content Language Place Holders
  * 
  * @param   string   $content  The content
  *
  * @return  string The content with the updated Language place holder
  * 
  */
 public function setCustomContentLang($content)
 {
     // insure string is not broken
     $content = str_replace('COM_###COMPONENT###', $this->langPrefix, $content);
     // set language data
     $langCheck[] = ComponentbuilderHelper::getAllBetween($content, "JText::_('", "'");
     $langCheck[] = ComponentbuilderHelper::getAllBetween($content, 'JText::_("', '"');
     $langCheck[] = ComponentbuilderHelper::getAllBetween($content, "JText::sprintf('", "'");
     $langCheck[] = ComponentbuilderHelper::getAllBetween($content, 'JText::sprintf("', '"');
     $langHolders = array();
     $lang = array();
     foreach ($langCheck as $langChecked) {
         if (ComponentbuilderHelper::checkArray($langChecked)) {
             $lang = array_merge($lang, $langChecked);
         }
     }
     if (ComponentbuilderHelper::checkArray($lang)) {
         foreach ($lang as $string) {
             // this is there to insure we dont break already added Language strings
             if (ComponentbuilderHelper::safeString($string, 'U') == $string) {
                 continue;
             }
             // only load if string is not already set
             $keyLang = $this->langPrefix . '_' . ComponentbuilderHelper::safeString($string, 'U');
             $this->langContent[$this->lang][$keyLang] = trim($string);
             $langHolders["JText::_('" . $string . "')"] = "JText::_('" . $keyLang . "')";
             $langHolders['JText::_("' . $string . '")'] = 'JText::_("' . $keyLang . '")';
             $langHolders["JText::sprintf('" . $string . "',"] = "JText::sprintf('" . $keyLang . "',";
             $langHolders['JText::sprintf("' . $string . '",'] = 'JText::sprintf("' . $keyLang . '",';
         }
         $content = str_replace(array_keys($langHolders), array_values($langHolders), $content);
     }
     return $content;
 }