Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE REQUEST] QOL features: splitting lang, visits counter #791

Open
Joduai opened this issue Aug 14, 2024 · 5 comments
Open

[FEATURE REQUEST] QOL features: splitting lang, visits counter #791

Joduai opened this issue Aug 14, 2024 · 5 comments

Comments

@Joduai
Copy link
Contributor

Joduai commented Aug 14, 2024

I'm still working on migratiion and during the process I was wondering if there are things I'm missing and just can't find the way of implementing them. Maybe you could shred some light on those matters

  1. support for separate language
    Setting a language in config applies to both frontend and backend. I switched the language to polish, and the translation is so bad (I presume it was made by a translator or taken from platform for community translation of software) that I was wondering if there's a way of splitting lang setting to have different language in frontend and backend. The more, if there's a way - maybe a function - I can call within theme functions file or template to check user's browser language, and load the apropriate lang.ini.

In getsimple cms there's a $LANG var that is used for frontend language inside theme files.


  1. disabling the page counter for logged in user
    While editing some of the imported articles I've realized that popular posts base on a simple page visit counter. This affects somewhat the purpose of popular_posts() funct. Is it a sufficient solution to use logged() func in functions.php to disable counting visits for logged user?
// Add page views count
function add_view($page)
{
	if (!login()) {
	...

  1. I asked earlier for the possibility of changing the main page for displaying blog posts when Enable blog URL option is active.
    It needs 3-4 changes in URIs inside functions.php thus I thought that implementing an option to set this "path" in config file would allow the user to get a functionality of "news" cms rather than only for blogging purpose. It won't change the purpose of using this cms but would allow additional workflows without interfering with source files.

  1. additional links in backend menu
    I had to add menu items in backend (pointing to for example external file uploader). Since there are custom config keys that can be used inside themes, I wonder if such keys could be automatically rendered inside admin theme. This way user could create a direct links to for example edit or view a certain page. Long time ago I created somewhat a simple notepad plugin for getsimple, that created a hidden page, and added menu item for editing this page and displaying its content in a modal window. It was very helpful during new post or article creation when I needed to check syntax or copy something I have saved in notepad-like page for future usage.

  1. hidden pages
    What is the best approach to create an editable but hidden from direct access pages?
    I've read some issues and questions about it, but didn't find any builtin' option.

There are many purposes for it, like custom but editable blocks on frontpage (custom config keys aren't always suitable for such things), pages that could be loaded in modal window, pages that could have own theme file with implemented forms displayed in modal window
etcetera,
Static pages are automatically added to the menu, thus user would need to create static menu in menu editor not to show such pages. I presume such pages are added to sitemap, thus it requires interfering with core files to add exceptions

I'm not fond of using draft type of pages for such things in any cms. It's not the base purpose of such pages.

Adding such pages to a fixed category would also need to mess with core files to add exceptions in displaying such pages, adding them to rss, sitemap and so on.

I wondered if there's an option to set pages as hidden. Something like custom config keys that could be used during post creation, and would store their content in page.md like tags or category, maybe something like
Or just a hardcoded checkbox "hidden page" in post options that would automatically add exception in foreach loops used in template files.

For seo purposes I also miss the robots options related to applying noindex/nofollow/noarchive to page.


  1. Haven't found any issue about this, but I would like to point this out
    Since I'm used to save the page frequently during creation I'm not fond of the workflow that saving a page closes edit mode and redirects the user to posts list. I never trust auto saves functions as they turned out to be useless when I needed them the most - for example during browser crash or power failures. Saving a post should just save it without closing.

Next thing is that link to post isn't pointing to edit it but to view the post on front page. I already missclicked the small "edit" button couple times, and instead clicked on "delete". Made my palms sweat ;)
Maybe an additional button "view" along the [edit][delete] would do the thing, when post title would point to edit the post?

Thought also about adding a column to show post type, but text is a bit too wide, thus I wondered if using icons would be better with type in title attribute.
Any thoughts about this?


  1. thumbnails generation

I tried the updated functions and dispatch files to check thumbnail generation, which is a must have feature, and it's great that it was implemented.
Basically it works as supposed, but only when image type posts contain full url to img with https://domain/
Generating a thumb when post has a relative /path/to/dir/img leads to php warning file_get_contents(): open_basedir restriction in effect. As a quick workaround I had to use full path to img in:

/* read the source image */
$source_image = imagecreatefromstring(file_get_contents("/home/user/domain/".$src));
@danpros
Copy link
Owner

danpros commented Aug 15, 2024

  1. To fix the translation you can edit the ini file inside lang folder or you can create the new one.

  2. Yes htmly is very simple actually, mostly is just glob the files, save the result as index file, than filter it. This is good idea, only record the hit for non logged user.

  3. So custom url for the blog index? creating new config blog.path seems good solutions.

  4. To modify the theme on the admin page we have to change it in system/admin/views so we have to add it manually.

  5. For the hidden page, the best approach is to put it in a folder, for example "hidden", the solution is the same as for drafts, and this is not implemented in htmly yet. It's interesting, so let's see how it goes in the future. Currently I am also implementing this kind of thing on my htmly website for the frontpage (editable blocks on frontpage).

  6. Maybe we can create a new config, for example giving an option where to go when we save a post. At the moment it redirected depend on query string parameter.

  7. In the future this can be improved, currently when uploading it always uses absolute url for the image.

@Joduai
Copy link
Contributor Author

Joduai commented Aug 15, 2024

ad1. yes, I'm working on it slowly, translating software to PL leads often to headache. I need to work on it on a fresh file as using current state is more problematic.
Anyway, the whole question is about the way of splitting frontend from backend language. Is there any way of doing it?
This isn't a big nuisance, but having such functionality could bring internationalization to items like headers or custom blocks pointed by you in one of the following points.

ad.2. maybe adding an option to stay logged in for longer time than browser session (or default php settings on shared hosts) would also be a good idea?

ad.3 great to hear that :)

ad.4 that's what I've done, but changes obviously won't last after upadate.
Thus any ways of adding custom elements would be great.

btw. shouldn't backup function also store site config? If we change default options add for example add custom keys, and use them in template, they will be lost during import into a new htmly instance.


ad5. ohh great you already thought about custom blocks. Could you shred some light about the future workflow?
I suppose it's going to be a way of adding new boxes with markdown support, along with generating code like custom_block('name'); to add within template file along with parsing its markdown, stored in own dir?

ad.6 additional config option in "config>writing" sounds great.
Stay in edit mode, redirect to posts list, view post - having those basic possibilities after saving would be nice.
How about ajax save? This way after reload editor view would stayin the same position without the need to scroll to bottom or edited text.


ad.7. I ended up with using user dir along with checking path to img

$source_image = imagecreatefromstring(file_get_contents(getcwd() . str_replace(site_url(), '/', $src)));

probably checking first if path to img is absolute or relative, and then either base on default $source_img or use above change would be better, rather than ending up with relative path to img.

maybe a bit late, but wouldn't allowing the user to switch between absolute and relative links be an option to reconsider for future versions? Option could be available only for fresh installations before adding content.

@Joduai
Copy link
Contributor Author

Joduai commented Aug 15, 2024

I couldn't remind myself why exactly did I ask for hidden pages, and I completely forgot that I wanted to create a template to display archive page with all posts, and a page with all defined categories and their descriptions. Maybe also a whole list of tags and links to related pages.

Currently the URI to /archives and /categories shows 404 page and the only approach I can think of is by creating 2 static pages: archive and categories, and create static--archive/categories.html.php. But it requiers creating a custom menu.

Maybe you already have a better idea or working solution?

@Joduai
Copy link
Contributor Author

Joduai commented Aug 20, 2024

After finding out in #793 that sitemap.static.xml lacks subpages I've changed a bit sitemap_page_path() function:

// Return static page path for sitemap
function sitemap_page_path()
{
	$posts = get_static_pages();

	$urlSubP = array();
	$tmp = array();

	if (!empty($posts)) {

        foreach ($posts as $index => $v) {

            $post = new stdClass;
            
            $fn = explode('.', $v['filename']);
            
            if (isset($fn[1])) {
                $filename = $fn[1];
            } else {
                $filename= $v['filename'];
            }
	
			$subPages = get_static_subpages($filename);

			foreach ($subPages as $index => $sp) {
				
				$subpost = new stdClass;
				
				$bs = explode('.', $sp['filename']);
				
				if (isset($bs[1])) {
					$baseSub = $bs[1];
				} else {
					$baseSub= $sp['filename'];
				}
				
				$urlSubP[] = $filename. "/" .$baseSub;
				$subfile  = $sp['dirname'] . '/' . $sp['basename'];
				$subpost->url =  site_url() .  $urlSubP[$index];
				$subpost->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($subfile)));

				$tmp[] = $subpost;
			}			 
			 
			$file = $v['dirname'] . '/' . $v['basename'];
			$post->url = site_url() . $filename;
			$post->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($file)));
			$tmp[] = $post;
			
        }
    }
   return $tmp;
}

@Joduai
Copy link
Contributor Author

Joduai commented Aug 21, 2024

As for disabling the page counter for logged in user in point 2, I went a bit further as add_view($page) func counts every page refresh, bots, and crawlers. Exceptions doesn't count common webcrawler's visits, check if user agent is set and not empty (assuming it's a true visitor) counting the same page hit/refresh only once per session.


function add_view($page)
{
	$dir = 'content/data/';
	if (!is_dir($dir)) {
		mkdir($dir, 0775, true);
	}
	
	$filename = "content/data/views.json";
	
	$current_page = $_SERVER['REQUEST_URI'];
	
	if (!login() && isset($_SERVER['HTTP_USER_AGENT']) && !empty($_SERVER['HTTP_USER_AGENT'])) 
	{
    // List of common bot user agents
		$bots = [
			'Googlebot','Bingbot','Slurp','DuckDuckBot','Baiduspider','YandexBot','Sogou','Exabot','facebot','ia_archiver','MJ12bot','AhrefsBot','SemrushBot','DotBot','MegaIndex','SeznamBot','PetalBot','Siteliner'
		];

		// Get the user agent
		$userAgent = $_SERVER['HTTP_USER_AGENT'];

		$isBot = false;
		foreach ($bots as $bot) {
			if (stripos($userAgent, $bot) !== false) {
				$isBot = true;
				break;
			}
		}	
		// If it's not a bot and the current page hasn't been counted yet, count the visit
		if (!$isBot && !isset($_SESSION['counted_pages'][$current_page])) {

			$views = array();
			if (file_exists($filename)) {
				$views = json_decode(file_get_data($filename), true);
			}
			if (isset($views[$page])) {
				$views[$page]++;
				save_json_pretty($filename, $views);
			} else {
				if (isset($views['flock_fail'])) {
					return;
				} else {
					$views[$page] = 1;
					save_json_pretty($filename, $views);
				}
			}
			
			$_SESSION['counted_pages'][$current_page] = true;
		}
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants