/** * Adds Published filtering on articles get_lang_list() call * * @param bool * @param null * */ protected function filter_on_published($on = TRUE, $lang = NULL) { if ($on === TRUE) { $this->{$this->db_group}->where($this->parent_table . '.online', '1'); if ($lang !== NULL && count(Settings::get_online_languages()) > 1) { $this->{$this->db_group}->where($this->lang_table . '.online', '1'); } $this->{$this->db_group}->where('((article.publish_off > ', 'now()', FALSE); $this->{$this->db_group}->or_where('article.publish_off = ', '0)', FALSE); $this->{$this->db_group}->where('(article.publish_on < ', 'now()', FALSE); $this->{$this->db_group}->or_where('article.publish_on = ', '0))', FALSE); } }
/** * Show the feed * * @access public * @return parsed view */ function feed($lang = FALSE) { $id_pages = explode(',', config_item('module_rss_pages')); $articles = $this->rss_model->get_articles($id_pages, $lang); // Articles ID array $articles_id = array(); foreach ($articles as $article) { $articles_id[] = $article['id_article']; } // Pages context, regarding the articles ID $pages_context = $this->page_model->get_lang_contexts($articles_id, $lang); // Add pages contexts data to articles foreach ($articles as &$article) { $contexts = array(); foreach ($pages_context as $context) { if ($context['id_article'] == $article['id_article']) { $contexts[] = $context; } } $page = array_shift($contexts); // Find the Main Parent if (!empty($contexts)) { foreach ($contexts as $context) { if ($context['main_parent'] == '1') { $page = $context; } } } // Article's URL $url = $article['url']; if (count(Settings::get_online_languages()) > 1) { $article['url'] = base_url() . $lang . '/' . $page['url'] . '/' . $url; } else { $article['url'] = base_url() . $page['url'] . '/' . $url; } } unset($article); // Sort the articles on date $kdate = array(); foreach ($articles as $key => $article) { $kdate[$key] = strtotime($article['date']); } // Sort the results by realm occurences DESC first, by date DESC second. array_multisort($kdate, SORT_DESC, $articles); // Output the feed $this->output->set_header("Content-Type: application/rss+xml; charset=UTF-8"); $this->load->view('rss', array('charset' => 'utf-8', 'language' => $lang, 'articles' => $articles)); }
public function get_urls() { $get_all_lang = FALSE; $langs = Settings::get_online_languages(); if (Settings::get('force_lang_urls') or count($langs) > 1) { $get_all_lang = TRUE; } $sql = "\r\n\t\t\tselect\r\n\t\t\t\tu.lang,\r\n\t\t\t\tu.path,\r\n\t\t\t\tp.priority,\r\n\t\t\t\tp.created,\r\n\t\t\t\tp.updated,\r\n\t\t\t\tp.publish_on,\r\n\t\t\t\tp.publish_off,\r\n\t\t\t\tp.logical_date\r\n\t\t\tfrom url u\r\n\t\t\tinner join page p on p.id_page = u.id_entity and p.has_url = 1\r\n\t\t\twhere\r\n\t\t\t\tu.type = 'page'\r\n\t\t\t\tand u.active = 1\r\n\t\t\t\tand u.canonical = 1\r\n\t\t\t\tand p.priority > 0\r\n\t\t\t\tand (p.publish_off = '0000-00-00 00:00:00' OR p.publish_off > now())\r\n\t\t"; if (!$get_all_lang) { $sql .= "\r\n\t\t\t\tand u.lang='" . Settings::get_lang('default') . "'\r\n\t\t\t"; } $sql .= "\r\n\t\t\tunion\r\n\r\n\t\t\tselect\r\n\t\t\t\tu.lang,\r\n\t\t\t\tu.path,\r\n\t\t\t\ta.priority,\r\n\t\t\t\ta.created,\r\n\t\t\t\ta.updated,\r\n\t\t\t\ta.publish_on,\r\n\t\t\t\ta.publish_off,\r\n\t\t\t\ta.logical_date\r\n\t\t\tfrom url u\r\n\t\t\tinner join article_lang al on al.id_article= u.id_entity and al.lang=u.lang and al.online=1\r\n\t\t\tinner join article a on a.id_article = al.id_article\r\n\t\t\twhere\r\n\t\t\t\tu.type = 'article'\r\n\t\t\t\tand u.active = 1\r\n\t\t\t\tand u.canonical = 1\r\n\t\t\t\tand a.indexed = 1\r\n\t\t\t\tand a.priority > 0\r\n\t\t\t\tand (a.publish_off = '0000-00-00 00:00:00' OR a.publish_off > now())\r\n\t\t"; if (!$get_all_lang) { $sql .= "\r\n\t\t\t\tand u.lang='" . Settings::get_lang('default') . "'\r\n\t\t\t"; } $query = $this->{$this->db_group}->query($sql); $data = $query->result_array(); return $data; }
/** * Returns HTML categories links wrapped by the given tag * * @TODO : Add the open and closing tag for each anchor. * Example : <li><a>... here is the anchor ... </a></li> * */ public static function tag_article_categories($tag) { $data = array(); // HTML Separatorof each category $separator = !empty($tag->attr['separator']) ? $tag->attr['separator'] : ' | '; // Make a link from each category or not. Default : TRUE $link = !empty($tag->attr['link']) && $tag->attr['link'] == 'false' ? FALSE : TRUE; // Field to return for each category. "title" by default, but can be "name", "subtitle' $field = !empty($tag->attr['field']) ? $tag->attr['field'] : 'title'; // don't display the lang URL (by default) $lang_url = ''; // Global tag and class, for memory $html_tag = !empty($tag->attr['tag']) ? $tag->attr['tag'] : FALSE; $class = !empty($tag->attr['class']) ? $tag->attr['class'] : FALSE; // Tag and class for each category, if set. $subtag = !empty($tag->attr['subtag']) ? $tag->attr['subtag'] : FALSE; $subclass = !empty($tag->attr['subclass']) ? ' class="' . $tag->attr['subclass'] . '"' : FALSE; // If lang attribute is set to TRUE, force the lang code to be in the URL // Usefull only if the website has only one language if (isset($tag->attr['lang']) && $tag->attr['lang'] == 'TRUE') { $lang_url = TRUE; } // Only returns the URL containing the lang code when languages > 1 // or atribute lang set to TRUE if (count(Settings::get_online_languages()) > 1 or $lang_url === TRUE) { $lang_url = Settings::get_lang() . '/'; } // Current page $page = $tag->locals->page; // Get the category URI segment from /config/ionize.php config file $uri_config = self::$ci->config->item('special_uri'); $uri_config = array_flip($uri_config); $category_uri = $uri_config['category']; // Get the categories from current article $categories = $tag->locals->article['categories']; // Build the anchor array foreach ($categories as $category) { $category_string = ''; if ($subtag !== FALSE) { // Set the local category, to get the class from current category $tag->locals->category = $category; $subclass = self::get_attribute($tag, 'subclass'); $subtag = self::get_attribute($tag, 'subtag'); // Replace the class and tag by the subclass and subtag $tag->attr['class'] = $subclass; $tag->attr['tag'] = $subtag; $category_string = self::wrap($tag, $category[$field]); } else { $category_string = $category[$field]; } $url = anchor(base_url() . $lang_url . $page['name'] . '/' . $category_uri . '/' . $category['name'], $category_string); if ($link == TRUE) { $category_string = $url; } $data[] = $category_string; // To make nested tags working... // $category['url'] = $url; // $tag->locals->category = $category; // $tag->expand(); } $tag->attr['tag'] = $html_tag; $tag->attr['class'] = $class; return self::wrap($tag, implode($separator, $data)); }
/** * Constructor * */ public function __construct() { parent::__construct(); // $this->output->enable_profiler(true); // Unlock filtering if admin or editor users is logged in // $this->load->library('connect'); $this->connect = Connect::get_instance(); // Libraries $this->load->library('structure'); $this->load->library('widget'); // FTL parser // require_once APPPATH.'libraries/ftl/parser.php'; // Models // $this->load->model('structure_model', '', true); $this->load->model('menu_model', '', true); // Modules config $this->get_modules_config(); /* * Installed modules * */ require APPPATH . 'config/modules.php'; $installed_modules = $modules; foreach ($installed_modules as $module) { // Path to Module Finder::add_path(MODPATH . $module . '/'); } /* * Theme * */ // Set the current theme Theme::set_theme(Settings::get('theme')); // Theme config file // Overwrite Ionize standard config. if (is_file($file = Theme::get_theme_path() . 'config/config.php')) { include $file; if (!empty($config)) { foreach ($config as $k => $v) { $this->config->set_item($k, $v); } unset($config); } } /* * Menus * */ Settings::set('menus', $this->menu_model->get_list()); /* * Language * */ // Get all the website languages from DB and store them into config file "languages" key $languages = $this->settings_model->get_languages(); // Put all DB languages array to Settings Settings::set_languages($languages); // Set all languages online if conected as editor or more if (Connect()->is('editors', true)) { Settings::set_all_languages_online(); } // Simple languages code array, used to detect if Routers found language is in DB languages $online_lang_codes = array(); foreach (Settings::get_online_languages() as $language) { $online_lang_codes[] = $language['lang']; } // If Router detected that the lang code is not in DB languages, set it to the DB default one if (!in_array(config_item('language_abbr'), $online_lang_codes)) { // Settings::get_lang('default') returns the DB default lang code Settings::set('current_lang', Settings::get_lang('default')); $this->config->set_item('language_abbr', Settings::get_lang('default')); } else { // Store the current lang code (found by Router) to Settings Settings::set('current_lang', config_item('language_abbr')); } // Lang dependant settings for the current language : Meta, etc. Settings::set_settings_from_list($this->settings_model->get_lang_settings(config_item('language_abbr')), 'name', 'content'); /* * Static language * */ $lang_folder = Theme::get_theme_path() . 'language/' . Settings::get_lang() . '/'; $lang_files = array(); // Core languages files : Including except "admin_lang.php" if (is_dir(APPPATH . 'language/' . Settings::get_lang())) { $lang_files = glob(APPPATH . 'language/' . Settings::get_lang() . '/*_lang.php', GLOB_BRACE); foreach ($lang_files as $key => $lang_file) { if ($lang_file == APPPATH . 'language/' . Settings::get_lang() . '/admin_lang.php') { unset($lang_files[$key]); } } } // Theme languages files : Including. Can be empty $lf = glob(FCPATH . Theme::get_theme_path() . 'language/' . Settings::get_lang() . '/*_lang.php'); if (!empty($lf)) { $lang_files = array_merge($lf, (array) $lang_files); } // Modules foreach ($installed_modules as $module) { // Languages files : Including. Can be empty $lang_file = MODPATH . $module . '/language/' . Settings::get_lang() . '/' . strtolower($module) . '_lang.php'; array_push($lang_files, $lang_file); } // Widgets languages translations loading // Now done by the Widget library // Load all modules lang files if (!empty($lang_files)) { foreach ($lang_files as $l) { if (is_file($l) && '.' . end(explode('.', $l)) == EXT) { include $l; if (!empty($lang)) { foreach ($lang as $key => $translation) { // If the term doesn't exists if (!isset($this->lang->language[$key])) { $this->lang->language[$key] = $translation; } else { // Only replace by default (theme vs. module) if the translation is empty if (empty($this->lang->language[$key])) { $this->lang->language[$key] = $translation; } } } unset($lang); } } } } require_once APPPATH . 'libraries/Tagmanager.php'; }
/** * Filters the article on published one * * @param bool $on * @param null $lang * */ protected function _filter_on_published($on = TRUE, $lang = NULL) { if ($on === TRUE) { $this->{$this->db_group}->join('article_lang', 'article_lang.id_article = article.id_article', 'left'); if (!is_null($lang)) { $this->{$this->db_group}->where('article_lang.lang', $lang); } $this->{$this->db_group}->where('page_article.online', '1'); if ($lang !== NULL && count(Settings::get_online_languages()) > 1) { $this->{$this->db_group}->where('article_lang.online', '1'); } $this->{$this->db_group}->where('((article.publish_off > ', 'now()', FALSE); $this->{$this->db_group}->or_where('article.publish_off = ', '0)', FALSE); $this->{$this->db_group}->where('(article.publish_on < ', 'now()', FALSE); $this->{$this->db_group}->or_where('article.publish_on = ', '0))', FALSE); } }
public static function get_base_url() { if (Authority::can('access', 'admin') && Settings::get('display_front_offline_content') == 1) { Settings::set_all_languages_online(); } if (count(Settings::get_online_languages()) > 1) { return base_url() . Settings::get_lang() . '/'; } return base_url(); }
/** * Inits articles URLs * Get the contexts of all given articles and define each article correct URL * * @param $articles * */ public function init_articles_urls(&$articles) { // Page URL key to use $page_url_key = config_item('url_mode') == 'short' ? 'url' : 'path'; // Array of all articles IDs $articles_id = array(); foreach ($articles as $article) { $articles_id[] = $article['id_article']; } // Articles contexts of all articles $pages_context = self::$ci->page_model->get_lang_contexts($articles_id, Settings::get_lang('current')); // Add pages contexts data to articles foreach ($articles as &$article) { $contexts = array(); foreach ($pages_context as $context) { if ($context['id_article'] == $article['id_article']) { $contexts[] = $context; } } $page = array_shift($contexts); // Get the context of the Main Parent if (!empty($contexts)) { foreach ($contexts as $context) { if ($context['main_parent'] == '1') { $page = $context; } } } // Basic article URL : its lang URL (without "http://") $url = $article['url']; // Link ? if ($article['link_type'] != '') { // External if ($article['link_type'] == 'external') { $article['absolute_url'] = $article['link']; } else { if ($article['link_type'] == 'email') { $article['absolute_url'] = auto_link($article['link'], 'both', TRUE); } else { // Article if ($article['link_type'] == 'article') { // Get the article to which this page links $rel = explode('.', $article['link_id']); $target_article = self::$ci->article_model->get_context($rel[1], $rel[0], Settings::get_lang('current')); // Of course, only if not empty... if (!empty($target_article)) { // Get the article's parent page $parent_page = self::$ci->page_model->get_by_id($rel[0], Settings::get_lang('current')); if (!empty($parent_page)) { $article['absolute_url'] = $parent_page[$page_url_key] . '/' . $target_article['url']; } } } else { $target_page = self::$ci->page_model->get_by_id($article['link_id'], Settings::get_lang('current')); // If target page is offline, 'path' is not set if (isset($target_page[$page_url_key])) { $article['absolute_url'] = $target_page[$page_url_key]; } else { $article['absolute_url'] = '#'; } } $article['relative_url'] = $article['absolute_url']; $article['relative_lang_url'] = $article['absolute_url']; // Correct the URL : Lang + Base URL if (count(Settings::get_online_languages()) > 1 or Settings::get('force_lang_urls') == '1') { $article['absolute_url'] = Settings::get_lang('current') . '/' . $article['absolute_url']; $article['relative_lang_url'] = $article['absolute_url']; } $article['absolute_url'] = base_url() . $article['absolute_url']; } } } else { $article['relative_url'] = $article['relative_lang_url'] = $page[$page_url_key] . '/' . $url; if (count(Settings::get_online_languages()) > 1 or Settings::get('force_lang_urls') == '1') { $article['relative_lang_url'] = Settings::get_lang('current') . '/' . $article['relative_url']; $article['absolute_url'] = base_url() . $article['relative_lang_url']; } else { $article['absolute_url'] = base_url() . $article['relative_url']; } } } }
/** * Languages tag * * @param FTL_Binding * * @return null|string * * @usage <ion:languages [helper="helper:helper_method"]> * ... * <ion:languages> * */ public static function tag_languages(FTL_Binding $tag) { $languages = Authority::can('access', 'admin') && Settings::get('display_front_offline_content') == 1 ? Settings::get_languages() : Settings::get_online_languages(); $page = self::registry('page'); $article = self::registry('article'); // Current active language class $active_class = $tag->getAttribute('active_class', 'active'); // Ignore current language in output $ignore_current = $tag->getAttribute('ignore_current'); // helper $helper = $tag->getAttribute('helper'); $str = ''; $tag->set('count', count($languages)); foreach ($languages as $idx => &$lang) { $lang_code = $lang['lang']; $p_data = $page['languages'][$lang_code]; if ($ignore_current == TRUE && $lang_code == Settings::get_lang('current')) { continue; } // Correct the Home page URL if ($p_data['online'] == 1 or $p_data['online'] == 0 && Authority::can('access', 'admin') && Settings::get('display_front_offline_content') == 1) { if ($page['home'] != 1) { $lang['absolute_url'] = !empty($page['absolute_urls'][$lang_code]) ? $page['absolute_urls'][$lang_code] : base_url() . $lang_code; } else { $lang['absolute_url'] = base_url() . $lang_code; } } else { $lang['absolute_url'] = NULL; } $lang['active_class'] = $lang_code == Settings::get_lang('current') ? $active_class : ''; $lang['is_active'] = $lang_code == Settings::get_lang('current'); $lang['id'] = $lang_code; if (!is_null($article)) { $a_data = $article['languages'][$lang_code]; if (!is_null($a_data['url']) && $a_data['online'] == 1 or $a_data['online'] == 0 && Authority::can('access', 'admin') && Settings::get('display_front_offline_content') == 1) { if ($page['home'] != 1) { $lang['absolute_url'] .= '/' . $a_data['url']; } else { $lang['absolute_url'] .= '/' . $page['urls'][$lang_code] . '/' . $a_data['url']; } } else { $lang['absolute_url'] = NULL; } } // Tag locals $tag->set('language', $lang); $tag->set('id', $lang_code); $tag->set('absolute_url', $lang['absolute_url']); $tag->set('active_class', $lang['active_class']); $tag->set('is_active', $lang['is_active']); $tag->set('index', $idx); if (!is_null($lang['absolute_url'])) { $str .= $tag->expand(); } } // Try to return the helper function result if ($str != '' && !is_null($helper)) { $helper_function = substr(strrchr($helper, ':'), 1) ? substr(strrchr($helper, ':'), 1) : 'get_language_navigation'; $helper = strpos($helper, ':') !== FALSE ? substr($helper, 0, strpos($helper, ':')) : $helper; self::$ci->load->helper($helper); if (function_exists($helper_function)) { $nav = call_user_func($helper_function, $languages); return self::wrap($tag, $nav); } } return self::wrap($tag, $str); }
/** * Multilingual Sitemap build * Author: Bhagya Silva (http://www.about.me/bhagyas) * Uses the lib : http://signalkraft.com/sitemaps-for-codeigniter * @param bool $force */ function build_multilingual_sitemap($force = FALSE) { $ci =& get_instance(); $ci->config->load('sitemaps'); $ci->load->model('notification_model', '', TRUE); $auto_create = config_item('sitemaps_auto_create'); if ($auto_create or $force) { $ci->load->library('sitemaps'); $ci->load->model('sitemap_model', '', TRUE); $get_all_lang = FALSE; $langs = Settings::get_online_languages(); if (Settings::get('force_lang_urls') or count($langs) > 1) { $get_all_lang = TRUE; } $urls = $ci->sitemap_model->get_multilingual_urls(); $multilingual_urls = array(); //iterate every url and build a map based on the key foreach ($urls as $url) { $url['date'] = $url['created']; if (strtotime($url['updated']) > strtotime($url['date'])) { $url['date'] = $url['updated']; } if (strtotime($url['publish_on']) > strtotime($url['date'])) { $url['date'] = $url['publish_on']; } if (strtotime($url['logical_date']) > strtotime($url['date'])) { $url['date'] = $url['logical_date']; } $loc = $get_all_lang == TRUE ? base_url() . $url['lang'] . '/' . $url['path'] : base_url() . $url['path']; $alternative_urls = array(); foreach ($urls as $other_url) { if ($other_url['lang'] != $url['lang'] && $other_url['id_'] == $url['id_']) { $other_loc = $get_all_lang == TRUE ? base_url() . $other_url['lang'] . '/' . $other_url['path'] : base_url() . $other_url['path']; $other_lang = $other_url['lang']; $alternative_urls[$other_lang] = $other_loc; } } $item = array('loc' => $loc, 'lang' => $url['lang'], 'lastmod' => date("c", strtotime($url['date'])), 'changefreq' => 'weekly', 'priority' => number_format($url['priority'] / 10, 1, '.', ''), 'alternative_urls' => $alternative_urls); array_push($multilingual_urls, $url['id_'], $item); $ci->sitemaps->add_item($item); } $ci->sitemaps->build_multilingual('sitemap.xml'); // Set notifications as read $ci->notification_model->set_code_as_read('sitemap_refresh'); } else { // Create one notification : The sitemap should be rebuild ! $ci->notification_model->create_notification(lang('ionize_notification_title_sitemap_refresh'), lang('ionize_notification_message_sitemap_refresh'), 'sitemap_refresh', 'System', TRUE); } }
/** * Languages tag * * @param FTL_Binding The binded tag to parse * */ public static function tag_languages($tag) { $languages = Settings::get_online_languages(); // $infos = self::get_url_infos(); // Current active language class $active_class = isset($tag->attr['active_class']) ? $tag->attr['active_class'] : 'active'; // helper $helper = isset($tag->attr['helper']) ? $tag->attr['helper'] : 'navigation'; // No helper ? $no_helper = isset($tag->attr['no_helper']) ? TRUE : FALSE; $str = ''; foreach ($languages as &$lang) { $tag->locals->lang = $lang; $tag->locals->url = $lang['url'] = $tag->locals->page['absolute_urls'][$lang['lang']]; $tag->locals->active = $lang['active_class'] = $lang['lang'] == Settings::get_lang('current') ? $active_class : ''; if (Connect()->is('editors', TRUE) or $lang['online'] == 1) { $str .= $tag->expand(); } } // Get helper method $helper_function = substr(strrchr($helper, ':'), 1) ? substr(strrchr($helper, ':'), 1) : 'get_language_navigation'; $helper = strpos($helper, ':') !== FALSE ? substr($helper, 0, strpos($helper, ':')) : $helper; // load the helper self::$ci->load->helper($helper); // Return the helper function result if (function_exists($helper_function) && $no_helper === FALSE) { $nav = call_user_func($helper_function, $languages); return self::wrap($tag, $nav); } else { return self::wrap($tag, $str); } }
/** * Sitemap build * Uses the lib : http://signalkraft.com/sitemaps-for-codeigniter * */ function build_sitemap($force = FALSE) { $ci =& get_instance(); $ci->config->load('sitemaps'); $ci->load->model('notification_model', '', TRUE); $auto_create = config_item('sitemaps_auto_create'); if ($auto_create or $force) { $ci->load->library('sitemaps'); $ci->load->model('sitemap_model', '', TRUE); $get_all_lang = FALSE; $langs = Settings::get_online_languages(); if (Settings::get('force_lang_urls') or count($langs) > 1) { $get_all_lang = TRUE; } $urls = $ci->sitemap_model->get_urls(); foreach ($urls as $url) { $url['date'] = $url['created']; if (strtotime($url['updated']) > strtotime($url['date'])) { $url['date'] = $url['updated']; } if (strtotime($url['publish_on']) > strtotime($url['date'])) { $url['date'] = $url['publish_on']; } if (strtotime($url['logical_date']) > strtotime($url['date'])) { $url['date'] = $url['logical_date']; } $loc = $get_all_lang == TRUE ? base_url() . $url['lang'] . '/' . $url['path'] : base_url() . $url['path']; $item = array('loc' => $loc, 'lastmod' => date("c", strtotime($url['date'])), 'changefreq' => 'weekly', 'priority' => number_format($url['priority'] / 10, 1, '.', '')); $ci->sitemaps->add_item($item); } /* $langs = Settings::get_online_languages(); $full = (config_item('url_mode') == 'full') ? TRUE : FALSE; $default_lang = config_item('default_lang_code'); if (count($langs) > 1 OR Settings::get('force_lang_urls') == '1') { // Get pages $pages = array(); foreach($langs as $lang) { $pages[$lang['lang']] = $ci->sitemap_model->get_pages($lang['lang']); } foreach($langs as $lang) { // Prepare pages : foreach($pages[$lang['lang']] as &$p) { $p['date'] = $p['created']; if (strtotime($p['updated']) > strtotime($p['date'])) $p['date'] = $p['updated']; if (strtotime($p['publish_on']) > strtotime($p['date'])) $p['date'] = $p['publish_on']; if (strtotime($p['logical_date']) > strtotime($p['date'])) $p['date'] = $p['logical_date']; } } foreach($langs as $lang) { $code = $lang['lang']; foreach($pages[$code] as $page) { $item = array( 'loc' => ($full == TRUE) ? base_url() . ($page['home'] == '1' && $code == $default_lang ? '' : $code . '/') . ($page['home'] != '1' ? $page['path'] : '') : base_url() . $code . '/' . ($page['home'] != '1' ? $page['url'] : ''), 'lastmod' => date("c", strtotime($page['date'])), 'changefreq' => 'weekly', 'priority' => number_format(($page['priority'] / 10), 1,'.','') ); $ci->sitemaps->add_item($item); } } } // No lang in URLs else { // Get pages $pages = $ci->sitemap_model->get_pages(); // Prepare pages : foreach($pages as &$p) { $p['date'] = $p['created']; if (strtotime($p['updated']) > strtotime($p['date'])) $p['date'] = $p['updated']; if (strtotime($p['publish_on']) > strtotime($p['date'])) $p['date'] = $p['publish_on']; if (strtotime($p['logical_date']) > strtotime($p['date'])) $p['date'] = $p['logical_date']; } foreach($pages as $page) { $item = array( 'loc' => ($full == TRUE) ? base_url() . ($page['home'] != '1' ? $page['path'] : '') : base_url() . ($page['home'] != '1' ? $page['url'] : ''), // ISO 8601 format - date("c") requires PHP5 'lastmod' => date("c", strtotime($page['date'])), 'changefreq' => 'weekly', 'priority' => number_format(($page['priority'] / 10), 1,'.','') ); $ci->sitemaps->add_item($item); } } */ $ci->sitemaps->build('sitemap.xml'); // Set notifications as read $ci->notification_model->set_code_as_read('sitemap_refresh'); } else { // Create one notification : The sitemap should be rebuild ! $ci->notification_model->create_notification(lang('ionize_notification_title_sitemap_refresh'), lang('ionize_notification_message_sitemap_refresh'), 'sitemap_refresh', 'System', TRUE); } }
function build_sitemap() { $ci =& get_instance(); $ci->load->library('sitemaps'); $ci->load->model('sitemap_model', '', TRUE); $langs = Settings::get_online_languages(); if (count($langs) > 1 or Settings::get('force_lang_urls') == '1') { // Get pages $pages = array(); foreach ($langs as $lang) { $pages[$lang['lang']] = $ci->sitemap_model->get_pages($lang['lang']); } foreach ($langs as $lang) { // Prepare pages : foreach ($pages[$lang['lang']] as &$p) { $p['date'] = $p['created']; if (strtotime($p['updated']) > strtotime($p['date'])) { $p['date'] = $p['updated']; } if (strtotime($p['publish_on']) > strtotime($p['date'])) { $p['date'] = $p['publish_on']; } if (strtotime($p['logical_date']) > strtotime($p['date'])) { $p['date'] = $p['logical_date']; } } } foreach ($langs as $lang) { $code = $lang['lang']; foreach ($pages[$code] as $page) { $item = array('loc' => base_url() . $code . '/' . $page['url'], 'lastmod' => date("c", strtotime($page['date'])), 'changefreq' => 'weekly', 'priority' => $page['priority'] / 10); $ci->sitemaps->add_item($item); } } } else { // Get pages $pages = $ci->sitemap_model->get_pages(); // Prepare pages : // foreach ($pages as &$p) { $p['date'] = $p['created']; if (strtotime($p['updated']) > strtotime($p['date'])) { $p['date'] = $p['updated']; } if (strtotime($p['publish_on']) > strtotime($p['date'])) { $p['date'] = $p['publish_on']; } if (strtotime($p['logical_date']) > strtotime($p['date'])) { $p['date'] = $p['logical_date']; } } foreach ($pages as $page) { $item = array('loc' => base_url() . $page['url'], 'lastmod' => date("c", strtotime($page['date'])), 'changefreq' => 'weekly', 'priority' => $page['priority'] / 10); $ci->sitemaps->add_item($item); } } $file_name = $ci->sitemaps->build('sitemap.xml'); }
/** * Element's items tag * * @param FTL_Binding $tag * * @return string * * @usage With "stickers" as your definition name : * <ion:static:stickers:items /> */ public static function tag_static_items(FTL_Binding $tag) { $return = $tag->getAttribute('return'); $str = ''; // Limit ? $limit = $tag->getAttribute('limit') ? (int) $tag->getAttribute('limit') : FALSE; $items = $tag->get('items'); $tag->set('count', 0); // Process the elements if (!empty($items)) { if (is_null($return)) { $count = count($items); $limit = ($limit == FALSE or $limit > $count) ? $count : $limit; $tag->set('count', $limit); for ($i = 0; $i < $limit; $i++) { $item = $items[$i]; // item : One element instance $tag->set('item', $item); $tag->set('index', $i + 1); $tag->set('count', $limit); $str .= $tag->expand(); } $str = self::wrap($tag, $str); } else { if ($return == 'json') { // Ugly process of links in case // of link type extend fields // @todo: rewrite self::$ci->load->model('extend_fields_model', '', TRUE); if (count(Settings::get_online_languages()) > 1 or Settings::get('force_lang_urls') == '1') { $base_url = base_url() . Settings::get_lang('current') . '/'; } else { $base_url = base_url(); } foreach ($items as $k1 => $item) { foreach ($item['fields'] as $k2 => $field) { if ($field['html_element_type'] == 'link') { $items[$k1]['ion_urls'] = array(); $links = self::$ci->extend_fields_model->get_extend_link_list_from_content($field['content']); foreach ($links as $link) { $items[$k1]['ion_urls'][] = $base_url . $link['path']; } } } } // End @todo $str = json_encode($items, TRUE); $str = str_replace("'", "\\'", $str); } } } return $str; }
/** * Constructor * */ public function __construct() { parent::__construct(); $module_uri = $this->uri->segment(1); // Set Module's config $module_config = Modules()->get_module_config_from_uri($module_uri); foreach ($module_config as $item => $value) { $this->config->set_item($item, $value); } if (!empty($module_config)) { // Languages $online_lang_codes = array(); foreach (Settings::get_online_languages() as $language) { $online_lang_codes[] = $language['lang']; } // If the lang code detected by the Router is not in the DB languages, set it to the DB default one if (!in_array(config_item('detected_lang_code'), $online_lang_codes)) { Settings::set('current_lang', Settings::get_lang('default')); $this->config->set_item('detected_lang_code', Settings::get_lang('default')); } else { // Store the current lang code (found by Router) to Settings Settings::set('current_lang', config_item('detected_lang_code')); } // Set the current theme Theme::set_theme(Settings::get('theme')); // Load Theme Events library if (is_file($file = FCPATH . Theme::get_theme_path() . 'libraries/theme_events.php')) { Event::load_event_library($file); } // Static translations $lang_files = array(); $lang_folder = APPPATH . 'language/' . Settings::get_lang(); // Core languages files : Including except "admin_lang.php" if (is_dir($lang_folder)) { $lang_files = glob($lang_folder . '/*_lang.php', GLOB_BRACE); foreach ($lang_files as $key => $lang_file) { if ($lang_file == $lang_folder . '/admin_lang.php') { unset($lang_files[$key]); } } } // Check if theme lang folder exist $theme_lang_folder = FCPATH . Theme::get_theme_path() . 'language/' . Settings::get_lang() . '/'; if (file_exists($theme_lang_folder)) { // Theme static translations $lf = glob($theme_lang_folder . '*_lang.php'); foreach ($lf as $key => $tlf) { if (basename($tlf) === 'theme_lang.php') { unset($lf[$key]); array_unshift($lf, $tlf); break; } } if (!empty($lf)) { $lang_files = array_merge($lf, (array) $lang_files); } } // Module translation files $lang_file = MODPATH . $module_config['folder'] . '/language/' . Settings::get_lang('current') . '/' . $module_config['key'] . '_lang.php'; if (is_file($lang_file)) { array_push($lang_files, $lang_file); } // Load all lang files if (!empty($lang_files)) { foreach ($lang_files as $l) { if (is_file($l) && '.' . end(explode('.', $l)) == EXT) { include $l; if (!empty($lang)) { foreach ($lang as $key => $translation) { // If the term doesn't exists if (!isset($this->lang->language[$key]) or $this->lang->language[$key] == '') { $this->lang->language[$key] = $translation; } else { // Only replace by default (theme vs. module) if the translation is empty if (empty($this->lang->language[$key])) { $this->lang->language[$key] = $translation; } } } unset($lang); } } } } } }
/** * Inits the Absolutes URLs of each page * * @TODO : Rewrite the "absolute_urls" definition so that it takes the internal links in account. * * */ public static function init_absolute_urls(&$pages, $lang) { $short_mode = config_item('url_mode') === 'short'; $languages = Authority::can('access', 'admin') && Settings::get('display_front_offline_content') == 1 ? Settings::get_languages() : Settings::get_online_languages(); foreach ($pages as &$page) { // Set the page complete URL $page['absolute_url'] = ''; $url = $short_mode ? $page['url'] : $page['path']; // Link if ($page['link_type'] != '') { // External if (in_array($page['link_type'], array('external', 'anchor'))) { $page['absolute_url'] = $page['link']; } else { if ($page['link_type'] === 'email') { $page['absolute_url'] = auto_link($page['link'], 'both', TRUE); } else { // Article if ($page['link_type'] === 'article') { // Get the article to which this page links $rel = explode('.', $page['link_id']); $target_article = self::$ci->article_model->get_context($rel[1], $rel[0], $lang); // Of course, only if not empty... if (!empty($target_article)) { // Get the article's parent page $page['absolute_url'] = ''; foreach ($pages as $p) { if ($p['id_page'] == $target_article['id_page']) { $p_url = $short_mode ? $p['url'] : $p['path']; $page['absolute_url'] = $p_url . '/' . $target_article['url']; } } } } else { // Get the page to which the page links $page['absolute_url'] = ''; foreach ($pages as $p) { if ($p['id_page'] == $page['link_id']) { $page['absolute_url'] = $short_mode ? $p['url'] : $p['path']; } } } if (count($languages) > 1 or Settings::get('force_lang_urls') == '1') { $page['absolute_url'] = $lang . '/' . $page['absolute_url']; } $page['absolute_url'] = base_url() . $page['absolute_url']; } } } else { if (count($languages) > 1 or Settings::get('force_lang_urls') == '1') { // Home page : doesn't contains the page URL if ($page['home'] == 1) { // Default language : No language code in the URL for the home page // Other language : The home page has the lang code in URL if (Settings::get_lang('default') != $lang) { $page['absolute_url'] = $lang; } } else { // If page URL if already set because of a link, don't replace it. // $url = ($short_mode) ? $page['url'] : $page['path']; $page['absolute_url'] = $page['absolute_url'] != '' ? $lang . '/' . $page['absolute_url'] : $lang . '/' . $url; } $page['absolute_url'] = base_url() . $page['absolute_url']; // Set the lang code depending URL (used by language subtag) $page['absolute_urls'] = array(); } else { if ($page['home'] == 1) { $page['absolute_url'] = base_url(); } else { // $url = ($short_mode) ? $page['url'] : $page['path']; $page['absolute_url'] = base_url() . $url; } // Set the lang code depending URL (used by language subtag) $page['absolute_urls'][$lang] = $page['absolute_url']; } } // Explode the concatenated URLs infos $page_url_langs = explode(';', $page['url_langs']); $page_url_path = explode(';', $page['url_paths']); foreach ($languages as $language) { if ($page['home'] == 1) { // Default language : No language code in the URL for the home page if (Settings::get_lang('default') == $language['lang']) { $page['absolute_urls'][$language['lang']] = base_url(); } else { $page['absolute_urls'][$language['lang']] = base_url() . $language['lang']; } } else { if (!$short_mode) { // The index of the processed lang code will be the index of the path $index = array_search($language['lang'], $page_url_langs); $url = $index !== FALSE ? $page_url_path[$index] : ''; $page['absolute_urls'][$language['lang']] = base_url() . $language['lang'] . '/' . $url; } else { $page['absolute_urls'][$language['lang']] = base_url() . $language['lang'] . '/' . $page['urls'][$language['lang']]; } } } } }
public static function init_absolute_urls(&$pages, $lang) { foreach ($pages as &$page) { // Set the page complete URL $page['absolute_url'] = ''; // Link if ($page['link_type'] != '') { // External if ($page['link_type'] == 'external') { $page['absolute_url'] = $page['link']; } else { if ($page['link_type'] == 'email') { $page['absolute_url'] = auto_link($page['link'], 'both', TRUE); } else { // Article if ($page['link_type'] == 'article') { // Get the article to which this page links $rel = explode('.', $page['link_id']); $target_article = self::$ci->article_model->get_context($rel[1], $rel[0], $lang); // Of course, only if not empty... if (!empty($target_article)) { // Get the article's parent page $page['absolute_url'] = ''; foreach ($pages as $p) { if ($p['id_page'] == $target_article['id_page']) { $page['absolute_url'] = $p['url'] . '/' . $target_article['url']; } } } } else { // Get the page to which the page links // $target_page = array_values(array_filter($con->globals->pages, create_function('$row','return $row["id_page"] == "'. $page['link_id'] .'";'))); // if ( ! empty($target_page)) // { // $page['absolute_url'] = $target_page[0]['url']; // } $page['absolute_url'] = ''; foreach ($pages as $p) { if ($p['id_page'] == $page['link_id']) { $page['absolute_url'] = $p['url']; } } } if (count(Settings::get_online_languages()) > 1 or Settings::get('force_lang_urls') == '1') { $page['absolute_url'] = $lang . '/' . $page['absolute_url']; } $page['absolute_url'] = base_url() . $page['absolute_url']; } } } else { if (count(Settings::get_online_languages()) > 1 or Settings::get('force_lang_urls') == '1') { // Home page : doesn't contains the page URL if ($page['home'] == 1) { // Default language : No language code in the URL for the home page // Other language : The home page has the lang code in URL if (Settings::get_lang('default') != $lang) { $page['absolute_url'] = $lang; } } else { // If page URL if already set because of a link, don't replace it. $page['absolute_url'] = $page['absolute_url'] != '' ? $lang . '/' . $page['absolute_url'] : $lang . '/' . $page['url']; } $page['absolute_url'] = base_url() . $page['absolute_url']; // Set the lang code depending URL (used by language subtag) $page['absolute_urls'] = array(); foreach (Settings::get_online_languages() as $language) { if ($page['home'] == 1) { // Default language : No language code in the URL for the home page if (Settings::get_lang('default') == $language['lang']) { $page['absolute_urls'][$language['lang']] = base_url(); } else { $page['absolute_urls'][$language['lang']] = base_url() . $language['lang']; } } else { $page['absolute_urls'][$language['lang']] = base_url() . $language['lang'] . '/' . $page['urls'][$language['lang']]; } } } else { if ($page['home'] == 1) { $page['absolute_url'] = base_url(); } else { $page['absolute_url'] = base_url() . $page['url']; } // Set the lang code depending URL (used by language subtag) $page['absolute_urls'][$lang] = $page['absolute_url']; } } } }
/** * Returns the base URL of the website, with or without lang code in the URL * */ public static function tag_base_url($tag) { // don't display the lang URL (by default) $lang_url = false; // Set all languages online if connected as editor or more if (Connect()->is('editors', true)) { Settings::set_all_languages_online(); } if (isset($tag->attr['lang']) && strtolower($tag->attr['lang']) == 'true') { if (count(Settings::get_online_languages()) > 1) { // if the current lang is the default one : don't return the lang code if (Settings::get_lang() != Settings::get_lang('default')) { return base_url() . Settings::get_lang() . '/'; } } } return base_url(); }
/** * Returns the base URL of the website, with or without lang code in the URL * */ public static function tag_base_url($tag) { // don't display the lang URL (by default) $lang_url = false; // The lang code in the URL is forced by the tag $force_lang = isset($tag->attr['force_lang']) ? true : false; // Set all languages online if connected as editor or more if (Connect()->is('editors', true)) { Settings::set_all_languages_online(); } if (isset($tag->attr['lang']) && strtolower($tag->attr['lang']) == 'true' or $force_lang === true) { if (count(Settings::get_online_languages()) > 1) { // forces the lang code to be in the URL, for each language // if ($force_lang === true) // { return base_url() . Settings::get_lang() . '/'; // } // More intelligent : Detects if the current lang is the default one and don't return the lang code /* else { if (Settings::get_lang() != Settings::get_lang('default')) { return base_url() . Settings::get_lang() .'/'; } } */ } } return base_url(); }
echo ucfirst($language['lang']); ?> </a></li> <?php } ?> </ul> <div class="clear"></div> </div> <div id="permanentUrlTabContent" class="w160"> <?php foreach (Settings::get_languages() as $language) { ?> <?php $lang = count(Settings::get_online_languages()) > 1 ? $language['lang'] . '/' : ''; ?> <div class="tabcontent"> <textarea id="permanent_url_<?php echo $language['lang']; ?> " name="permanent_url_<?php echo $language['lang']; ?> " class="h40" style="border-top:none;width:142px;" onclick="javascript:this.select();" readonly="readonly"><?php echo base_url() . $lang; echo ${$language['lang']}['url']; ?> </textarea> </div> <?php
/** * Returns the Home URL * * @return string * */ public static function get_home_url() { // Set all languages online if connected as editor or more if (Authority::can('access', 'admin') && Settings::get('display_front_offline_content') == 1) { Settings::set_all_languages_online(); } if (count(Settings::get_online_languages()) > 1) { // if the current lang is the default one : don't return the lang code if (Settings::get_lang() != Settings::get_lang('default')) { return base_url() . Settings::get_lang() . '/'; } } return base_url(); }
/** * Filters the pages on published one * */ protected function filter_on_published($on = true, $lang = NULL) { if ($on === true) { $this->{$this->db_group}->where($this->table . '.online', '1'); if ($lang !== NULL && count(Settings::get_online_languages()) > 1) { $this->{$this->db_group}->where($this->lang_table . '.online', '1'); } $this->{$this->db_group}->where('((publish_off > ', 'now()', false); $this->{$this->db_group}->or_where('publish_off = ', '0)', false); $this->{$this->db_group}->where('(publish_on < ', 'now()', false); $this->{$this->db_group}->or_where('publish_on = ', '0))', false); } }