input; $action = $input->post->get('action', '', 'STRING'); if($action=='upload_image') { $this->upload_image(); return; } else if($action=='remove_image') { $this->remove_image(); return; } if ($_POST['data']) { $data = json_decode(json_encode($_POST['data']), true);; $action = $data['action']; $layoutName = ''; if (isset($data['layoutName'])) { $layoutName = $data['layoutName']; } $template = self::getTemplate()->template; $layoutPath = JPATH_SITE.'/templates/'.$template.'/layout/'; $filepath = $layoutPath.$layoutName; $report = array(); $report['action'] = 'none'; $report['status'] = 'false'; switch ($action) { case 'remove': if (file_exists($filepath)) { unlink($filepath); $report['action'] = 'remove'; $report['status'] = 'true'; } $report['layout'] = JFolder::files($layoutPath, '.json'); break; case 'save': if ($layoutName) { $layoutName = strtolower(str_replace(' ','-',$layoutName)); } $content = $data['content']; if ($content && $layoutName) { $file = fopen($layoutPath.$layoutName.'.json', 'wb'); fwrite($file, $content); fclose($file); } $report['layout'] = JFolder::files($layoutPath, '.json'); break; case 'load': if (file_exists($filepath)) { $content = file_get_contents($filepath); } if (isset($content) && $content) { echo $layoutHtml = self::loadNewLayout(json_decode($content)); } die(); break; case 'resetLayout': if($layoutName){ echo self::resetMenuLayout($layoutName); } die(); break; // Upload Image case 'upload_image': echo "Joomla"; die(); break; default: break; case 'voting': if (JSession::checkToken()) { return json_encode($report); } $rate = -1; $pk = 0; if (isset($data['user_rating'])) { $rate = (int)$data['user_rating']; } if (isset($data['id'])) { $id = str_replace('post_vote_','',$data['id']); $pk = (int)$id; } if ($rate >= 1 && $rate <= 5 && $id > 0) { $userIP = $_SERVER['REMOTE_ADDR']; $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('*') ->from($db->quoteName('#__content_rating')) ->where($db->quoteName('content_id') . ' = ' . (int) $pk); $db->setQuery($query); try { $rating = $db->loadObject(); } catch (RuntimeException $e) { return json_encode($report); } if (!$rating) { $query = $db->getQuery(true); $query->insert($db->quoteName('#__content_rating')) ->columns(array($db->quoteName('content_id'), $db->quoteName('lastip'), $db->quoteName('rating_sum'), $db->quoteName('rating_count'))) ->values((int) $pk . ', ' . $db->quote($userIP) . ',' . (int) $rate . ', 1'); $db->setQuery($query); try { $db->execute(); $data = self::getItemRating($pk); $rating = $data->rating; $report['action'] = $rating; $report['status'] = 'true'; return json_encode($report); } catch (RuntimeException $e) { return json_encode($report);; } } else { if ($userIP != ($rating->lastip)) { $query = $db->getQuery(true); $query->update($db->quoteName('#__content_rating')) ->set($db->quoteName('rating_count') . ' = rating_count + 1') ->set($db->quoteName('rating_sum') . ' = rating_sum + ' . (int) $rate) ->set($db->quoteName('lastip') . ' = ' . $db->quote($userIP)) ->where($db->quoteName('content_id') . ' = ' . (int) $pk); $db->setQuery($query); try { $db->execute(); $data = self::getItemRating($pk); $rating = $data->rating; $report['action'] = $rating; $report['status'] = 'true'; return json_encode($report); } catch (RuntimeException $e) { return json_encode($report); } } else { $report['status'] = 'invalid'; return json_encode($report); } } } $report['action'] = 'failed'; $report['status'] = 'false'; return json_encode($report); break; //Font variant case 'fontVariants': $template_path = JPATH_SITE . '/templates/' . self::getTemplate()->template . '/webfonts/webfonts.json'; $plugin_path = JPATH_PLUGINS . '/system/helix3/assets/webfonts/webfonts.json'; if(JFile::exists( $template_path )) { $json = JFile::read( $template_path ); } else { $json = JFile::read( $plugin_path ); } $webfonts = json_decode($json); $items = $webfonts->items; $output = array(); $fontVariants = ''; $fontSubsets = ''; foreach ($items as $item) { if($item->family==$layoutName) { //Variants foreach ($item->variants as $variant) { $fontVariants .= ''; } //Subsets foreach ($item->subsets as $subset) { $fontSubsets .= ''; } } } $output['variants'] = $fontVariants; $output['subsets'] = $fontSubsets; return json_encode($output); break; //Font variant case 'updateFonts': jimport( 'joomla.filesystem.folder' ); jimport('joomla.http.http'); $template_path = JPATH_SITE . '/templates/' . self::getTemplate()->template . '/webfonts'; if(!JFolder::exists( $template_path )) { JFolder::create( $template_path, 0755 ); } $tplRegistry = new JRegistry(); $tplParams = $tplRegistry->loadString(self::getTemplate()->params); $gfont_api = $tplParams->get('gfont_api', 'AIzaSyBVybAjpiMHzNyEm3ncA_RZ4WETKsLElDg'); $url = 'https://www.googleapis.com/webfonts/v1/webfonts?key='. $gfont_api; $http = new JHttp(); $str = $http->get($url); if($str->code == 200) { // if successfully updated if ( JFile::write( $template_path . '/webfonts.json', $str->body )) { echo "
Google Webfonts list successfully updated! Please refresh your browser.
"; } else { echo "Google Webfonts update failed. Please make sure that your template folder is writable.
"; } } elseif($str->code == 403) { // If got error $decode_msg = json_decode($str->body); if(isset(json_decode($str->body)->error->message) && $get_msg = json_decode($str->body)->error->message) { echo "". $get_msg ."
"; } } die(); break; //Template setting import case 'import': $template_id = filter_var( $data['template_id'], FILTER_VALIDATE_INT ); if ( !$template_id ) { die(); break; } $settings = $data['settings']; $db = JFactory::getDbo(); $query = $db->getQuery(true); $fields = array( $db->quoteName( 'params' ) . ' = ' . $db->quote( $settings ) ); $conditions = array( $db->quoteName( 'id' ) . ' = '. $db->quote( $template_id ), $db->quoteName('client_id') . ' = 0' ); $query->update($db->quoteName('#__template_styles'))->set($fields)->where($conditions); $db->setQuery($query); $db->execute(); die(); break; } return json_encode($report); } } static public function getItemRating($pk = 0){ $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('ROUND(rating_sum / rating_count, 0) AS rating, rating_count') ->from($db->quoteName('#__content_rating')) ->where($db->quoteName('content_id') . ' = ' . (int) $pk); $db->setQuery($query); $data = $db->loadObject(); return $data; } static public function resetMenuLayout($current_menu_id = 0){ if (!$current_menu_id) { return; } $items = self::menuItems(); $item = array(); if (isset($items[$current_menu_id]) && !empty($items[$current_menu_id])) { $item = $items[$current_menu_id]; } $menuItems = new JMenuSite; $no_child = true; $count = 0; $x_key = 0; $y_key = 0; $check_child = 0; $item_array = array(); foreach ($item as $key => $id){ $status = 0; if (isset($items[$id]) && is_array($items[$id])){ $no_child = false; $count = $count + 1; $check_child = $check_child+1; $status = 1; } if ($check_child === 2){ $y_key = 0; $x_key = $x_key + 1; $check_child = 1; } $item_array[$x_key][$y_key] = array($id,$status); $y_key = $y_key + 1; } if ($no_child === true){ $count = 1; } if($count > 4 && $count != 6){ $count = 4; } ob_start(); if($no_child === true) { echo ''; } else { echo ''; } $output = ob_get_contents(); ob_clean(); return $output; } static public function create_menu($current_menu_id) { $items = self::menuItems(); $menus = new JMenuSite; if (isset($items[$current_menu_id])) { $item = $items[$current_menu_id]; foreach ($item as $key => $item_id) { echo '