Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am planing to build a simple CMS (with PHP) for my own educational needs and I ran into a problem with design as I have never encountered this in any book or tutorial.
If I wanted to let used mess around the colors for example. How do I do that? The only idea I had was make a database with basically all such a options and then echo them to the site as normal CSS. But thet would mean it would load from DB every single time someone visits the webasite. It seems to me like it could overload the website. But again, I have never encountered such a problem. Or is there a way of doing this much more easily?
Thanks for every answer!
EDIT:
I would like to create a system that enables user to change css via CMS. For example background color, drop-down menu colors, text sizes, fonts and a lot of other stuff handeled by CSS. Simple customization.
So I was asking 2 questions.
How? What system should I use? No book/tutorial I read never covered editing CSS files using PHP so I have no idea how to do that. Or maybe there are better ways of doing it?
I had idea how I would store all customisable data. In database I wanted to know how big it can be and whether it would be a problem when posibly tens or maybe even houndreds of variables would be loading to the site.
EDIT2:
And btw I never worked with Wordpress or other CMS and I kind of expected that options like what I am looking for are present there, is that true? In my mind such a feature is essential for user inexperienced with computers. But from what I understand from link provided by Sam (http://css-tricks.com/css-variables-with-php/), it's not common. It's actually quite complicated thing and might harm performance of the website.
I hope I made my question clear now.
I know this has tons of downvotes, but you can cache your database queries. You can also mimic a CSS file using the header type in PHP. See http://css-tricks.com/css-variables-with-php/
This will allow the browser to cache the CSS file that was generated by PHP & MySQL. This means the database will only be called when the cache expires.
In terms of size you will never reach a limit with what you are describing.
Update
These sort of features are a bit unorthodox, using a cached version of the generated CSS file is basically mandatory.
What you can do is include a text editor within the CMS to edit the CSS file, each user can have their own CSS file that overrides the default one if changed. By letting them edit it directly they can change the layout themselves. You can even limit them to only changing colours / font-sizes etc.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I need to crawl a website and detect how many ads are on a page. I've crawled using PHPCrawl and saved the content to DB. How can I detect if a web page has ads above the fold?
Well simply put: You can't really. At least not in a simple way. There is many things to consider here and all of them are highly subjective to the web page you are crawling, the device used, etc. I'll try to explain some of the main issues you would need to work around.
Dynamic Content
The first big problem is, that you just have the HTML structure, which on itself gives no direct visual information. It would be, if we were in like 1990, but modern websites use CSS and JS to enhance their pages core structure. What you see in your browser is not just HTML rendered as is. It's subject to CSS styling and even JS induced code fragments, which can alter the page significantly. For example: Any page that has a so called AJAX loader, will output as a very simple HTML code block, that you would see in the crawler. But the real page is loaded AFTER this is rendered (from JS).
Viewport
What you described as "above the fold" is an arbitary term, that can't be defined globaly. A smartphone has a very different viewport than a desktop PC. Also most of modern websites use a very different structure for mobile, tablet and desktop devices. But let's say you just want to do it for desktop devices. You could define an average viewport over most used screen resolutions (which you may find on the internet). We will define it as 1366x786 for now (based on a quick google search). However you still only have a PHP script and an HTML string. Which brings us the next problem.
Rendering
What you see in your browser is actually the result of a complex system, that incooperates HTML and all of the linked ressouces to render a visual representation of the code you have crawled. Besides the core structure of the HTML string you got, any resource linked can (and will) chanfge how the content looks. They can even add more content based on a variety of conditions. So what you would need to get the actual visual information is a so called "headless browser". Only this can give you valid informations about what is actually visible inside the desired viewport. If you want to dig into that topic, a good starting point would be a distribution like "PhantomJS". However don't assume that this is an easy task. You still only have bits of data, no context whatsoever.
Context, or "What is an ad?"
Let's assume you have tackled all these problems and made a script that can actually interpret all the things you got from your crawler. You still need to know "What is an ad?". And thats a huge problem. Of course for you as a human it's easy to distinquish between what is part of the website and what is an ad. But translating that into code is more of an AI task than just a basic script. For example: The ads could (and are most of the time) loaded into a predfined container, after the actual page load. These in turn may only have a cryptic ID set that distinguishes them from the rest of the (actually valid) page content. If you are lucky, it has a class with a string like "advertisment", but you can't just define that as given. Ads are subject to all sorts of ad blockers, so they have a long history of trying to disquise themselves as good as possible. You will have a REALLY hard time figuring out what is an ad, and what is valid page content.
So, while I only tackled some of the problems you are going to run into, I want to say that it's not impossible. But you have to understand that you are at the most basic entry point and if you want to make a system that is actually working, you'll have to spend a LOT of time on finetuning and maybe even research on the AI field.
And to come back to your question: There is no simple answer for "How to detect if a page has ads". Because it is way more complex than you might think. Hope this helps.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm building a real estate website, and I want to have a page for every building in my database, so that I can find these in Google. I was wondering if I should create a static page for each of these, or if there's another way I can find them in Google.
EDIT:
I was rather wondering how I should structure these semi static/dynamic pages. I want to have a fixed title and description for the google results, but the photos and other info can be filled in via database info. Does this seem reasonable or am I overseeing things, or can this be done more efficiently?
Really, I'm just saying I want u fixed URL, title and meta description for google. I want the rest to be handled dynamically.
From your comments, I think you've misunderstood the relationship between files and URLs. When you, or Google, requests a URL, the web server can look at that URL and do whatever it likes with it. Whatever it returns is what shows in your browser, or in the Google search results.
The most obvious way for a web server to respond is to map the URL directly to a path on disk, and return the contents of that file, but that would mean no dynamic content ever appeared. The next obvious step is to run the program at that location, rather than serving its content, but that's still very limiting. Instead, the principle behind most modern websites is that the URL determines both a program to run, and parameters for that program.
So, in your case, the URL /property.php?id=42 might run the script property.php, which would look at the id parameter, and fetch the necessary content for property 42 - including the title, meta tags, pictures, etc - from wherever you have stored them in the database. With some extra server configuration, you can make /property/42-great-three-bed-apartment an alias for that same URL (note the 42 is still there, so we still have enough to look it up in the database).
This is basically how all modern websites work, including this one right here.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Looking for ideas on how to go about working with a large set of .html files (50,000+) that are preexisting.
What I am trying to accomplish is to be able to keep the same hierarchy, links etc... but add content to them via php or whatever etc..
To be able to organize or route them into a php application or my own cms. I have been thinking ways to do this and come up with a few ideas but hoping to get some feedback from some pros.
I really only need to create something that will get the data once and add it to a cms that I develop. I have a script that I wrote to be able to index and search etc.. but how to go about using the contents and adding to them while keeping structure has me swinging a little. Any thoughts?
UPDATE: I found some tips that made this easier for me as well
Use a .htacess file and ad:
AddType application/x-httpd-php .html .htm
Then I can add includes into those files, I am note sure where to put this in the config file yet but will update when I know.
If you were to use a CMS like Wordpress, assuming your content follows some sort of regular structure, you could recreate the HTML frame as templates and then write a script that parses each HTML file and creates a post based on criteria like the HTML file name.
You can even match the file name by setting the slug on post creation, though you'll need a server rewrite rule to drop the .htm(l) if you intend to keep all the backlinks to the site.
I'm oversimplifying of course, as with 50,000+ files it isn't a trivial job to move all the data.
Perhaps automate it using something like this: http://wordpress.org/extend/plugins/import-html-pages/
The way I would go about it is to keep the html in a function which you require. Separate them logically as:
function output_html_one($link_here, $or_link_there...) {...}
function output_html_two($other_links...) {...}
When you want to output them with the files you have, just call the function, and it will be sent out. I am sure others will give you preferences. This allows you to give them access to variables through arguments, which is a downside, but it keep everything organized and provides some clarity as you can separate the raw html from the logic in your code. I am very curious to see what others say.
EDIT: I added $user inside of html_header so its clearer. For example, lets say you might want to check if a user is logged in. This gives you a way to tailor your html. Then you go to the files which contains this, you can jump in and out of the php tags in order to add dynamic content.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm working on a site which requires a very simple CMS - basically there's a block of text on the homepage that needs to be editable by the client. Their current hosting plan doesn't allow for a database, and including one will cost an extra $X a month which I think is unnecessary for such a basic system.
The site is currently built using Codeignitor. I'm planning to write the CMS part of it using either flat PHP or TXT files, are there alternative methods worth considering, and what are the pros/cons?
Okay, so further to this, I've opted for a custom flatfile system. I looked at a few of the recommended non DB CMS systems and they seem quite good - particularly this one which I later found: http://get-simple.info/
The reason for building my own is mainly due to the fact that the site is already on the Codeignitor Framework, and I don't want to rebuild it using a different one.
So my question now is - if my system is storing data in two txt files: one for userdata and one for site content, are there massive security issues if I set the sitecontent file permissions to RW? The site is quite small and I can't imagine anyone would want to hack it, but I'd still like to know if there are any major security implications.
Try http://www.opensourcecms.com/
example of some that might interest you
PivotX
pluck
razorCMS
cushyCMS
its ftp's into your hosting account, reads your html, and looks for tags that have a class="cushy" and makes those content feilds editable. its good forwhat your wanting.
I once solved this problem by simply putting markers in an HTML file, as HTML comments, and then had my PHP script parse the file and insert the desired text in between the markers. Done this way, you need no other files other than the PHP that handles the form submission from the CMS and a static HTML page.
In words, read the file into a string, explode() the string using the marker as the delimiter, modify the second (if you have a single editable section enclosed by the markers) array element to contain the new text submitted by the user, then implode the array back into the string, then write the string back as the complete file.
What about sqlite? it is just a file, no need to install anything? But if this is also not welcome, you could just keep the contents in txt files and have a php to read it, put to your template.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
OK I'll try again, sorry if it's too simple for you; we all have to start somewhere.
I need to use a webpage to specify the layout of the newspaper ie header, footer and news areas. This is produced by an HTML page which I have created [the one with check boxes and a create button].
A second web page is to add content to the various components; again, I have the HTML page with 3 sections for input to the header, body, and footer, each with a save button. The content then needs to be output.
The information is to be stored in a MySQL database, but I only need to use the web forms I have already created in HTML to design the layout and add content. The database is to store the layout and content information.
Changes to the database tables should dynamically reflect changes in the presentation page.
The database I have already created has 6 linked tables so far [layout, header, footer, local,national and international]. I also know the MySQL code to link with the database, but not how to code to POST information to the database from the web pages via php handling to the database or GET information from the database.
Can anyone help?
What I've learnt so far:
If you create a CMS you'll gain tons of programming experience.
If you want to build a news portal for a real client avoid [1] and use an existing CMS.
Although there are a number of frameworks and cms's systems that you could use. The php commands you are looking for to interact with the database you will find here.
http://ca2.php.net/manual/en/function.mysql-query.php
I hope this helps.
It sounds like you are reinventing the while, and all the problems that will come long with it. May I suggest you use an existing CMS? There are a myriad of options, but some of the more famous that come to mind include...
Plone
Joomla
Drupal
TYPO3
WordPress
There is even a wikipedia page on the subject: Web content management systems
I am actually working on a similar project. Dont use an existing CMS... most cms are overkill for something this basic... It also gives you more control over everything and it is a great way for a beginner to learn PHP and how to work with databases... One tool I have found helpful is FCKeditor... It allows the client to create a detailed layout just as if they were using Word but will return HTML to you...
Look into:
drupal
wordpress
As starting points. Good luck.
I have had success using WordPress in this fashion and would recommend it.
This post was helpful to me doing something similar:
http://blueprintds.com/2008/03/13/top-10-wordpress-cms-plugins/
As far as composing a page with separate content sections there are several approaches to take. Here are 2 common ones.
Approach 1: Make your theme's page or index template pull the content from separate "pages" or "posts". Choosing the section to include based on either categories you set on the "page" or "post" meant to display in that section or a customfield value indicating they are to be displayed in a section. I like this approach cause you get the nice html wysiwyg editor and versioning for the content.
Example of template:
html
<? php /*call main pagecontent*/ ?>
html
<?php /*call 2nd section of pagecontent (posts where category = '2nd section' limit 1)*/ ?>
more html
<?php /*call 3rd section of pagecontent (posts where category = '3rd section' limit 1)*/ ?>
etc
Approach 2: Use custom fields for the separate content sections for a single post (number of disadvantages here but it might be more straightforward to get something quickly.)
If more detail is desired for the above let me know.
I'm doing something similar for a client. Because of deadlines and budgets I gave up and have to use an existing CMS. That is my advice for you on this project. But I'm sure you will continue to develop this CMS either on the side or for the project anyway so what you'll need to do is in addition to connecting to the database you'll just create a function to call data from the correct table. You use SQL syntax within a PHP function and you'll say pull content FROM tablename WHERE table column=correct row for the page. The guy who linked to the PHP manual sent you to the right page.
I must say developing your own CMS is not a bad idea like a lot of people keep saying for a number of reasons.
1. You learn a lot in the process
2. Many cms's have tons of overkill.
3. While they're all overkill they miss one important feature and thats content blocks. Pages may need more than one editable content area. Wordpress and the like only allow you one main section of the page to edit. Sure, they have dynamic sidebars and menus but that's not what we're looking for. We need a CMS that allows you to edit a handful of different content areas of a page. I'm creating my own CMS for just this purpose. I'm having problems separating the code in such a way that I can just call functions within different page templates bu that's another story. Anyway, use the info in that PHP manual link. I think that's exactly what you're looking for. In the meantime don't give up on that CMS and don't listen to everyone who says that the world doesn't need yet another one. It does. A barebones one that pulls more than one main content area from a DB into a page. That's all. No plugins, no overkill. Just chunks of content. Maybe share your source code when you're done so some people can learn?