- Always attribute third party images you might use on your own blogs and set an example first. If possible, write to the original copyright holder and ask for permission courteously. If by chance the original image copyright holder still asks you to remove their image, even if attributed, apologize and comply with their request.
- Never upload your own hi-resolution photographs to the internet directly. Always scale it down to a size where it will look horrible in print. Also keep the DPI resolution low (like 72 dpi or lower). Experiment with watermarking images so that the watermarks will be visible in print.
- Respect others' copyrights in the same way and don't quote other people's written material without permission and/or attribution.
Hari's Corner
Humour, comics, tech, law, software, reviews, essays, articles and HOWTOs intermingled with random philosophy now and thenPlagiarism by the print media
Filed under:
People and society by
Hari
Posted on Fri, Oct 3, 2008 at 08:45 IST (last updated: Fri, Oct 3, 2008 @ 09:12 IST)
Function to generate a pagination link list in PHP
Filed under:
Tutorials and HOWTOs by
Hari
Posted on Wed, Oct 1, 2008 at 12:04 IST (last updated: Sat, Apr 28, 2012 @ 09:01 IST)
SELECT's LIMIT and OFFSET mechanism) generating a list of navigable links for each page of data is another cup of tea.
Let's assume that you want to generate a list of pages in PHP. E.g. You need to create a blog navigation toolbar, with links to each page on the footer.
The assumption is that you have hundreds of pages to display and you cannot display each page in the navigation toolbar, because that would become unwieldy. What you want is actually a list looking like this below (bolded item is current page):
Page: 1 2 3 4 5 ... 100
Or if the page is in the middle of the the navigation
1 ... 70 71 72 73 74 75 76 78 79 ... 100
If the page is at the end of this list
1 ... 92 93 94 95 96 97 98 99 100
This navigation scheme is not perfect, but it is adequate for most purposes. The following PHP function creates an array of navigable links which can be easily used to create such a pagination. This can be used as a generic pagination function, because it accepts all necessary parameters (including the base URL as well as the query string to use), total number of pages, current page and pagination limit. The pagination limits how many pages are actually shown around the current page.
To use the function in a PHP page, you just have to simply walk through the array:<?php // Function to generate pagination array - that is a list of links // for pages navigation function paginate ($base_url, $query_str, $total_pages, $current_page, $paginate_limit) { // Array to store page link list $page_array = array (); // Show dots flag - where to show dots? $dotshow = true; // walk through the list of pages for ( $i = 1; $i <= $total_pages; $i ++ ) { // If first or last page or the page number falls // within the pagination limit // generate the links for these pages if ($i == 1 || $i == $total_pages || ($i >= $current_page - $paginate_limit && $i <= $current_page + $paginate_limit) ) { // reset the show dots flag $dotshow = true; // If it's the current page, leave out the link // otherwise set a URL field also if ($i != $current_page) $page_array[$i]['url'] = $base_url . "?" . $query_str . "=" . $i; $page_array[$i]['text'] = strval ($i); } // If ellipses dots are to be displayed // (page navigation skipped) else if ($dotshow == true) { // set it to false, so that more than one // set of ellipses is not displayed $dotshow = false; $page_array[$i]['text'] = "..."; } } // return the navigation array return $page_array; } ?>
The output of the above code will be<?php // To use the pagination function in a // PHP script to display the list of links // paginate 100 pages - current page is 50 and show // 5 links around the current page $pages = paginate ("myurl.php", "page", 100, 50, 5); ?> <p>Pages: <?php // list display foreach ($pages as $page) { // If page has a link if (isset ($page['url'])) { ?> <a href="<?php echo $page['url']?>"> <?php echo $page['text'] ?> </a> <?php } // no link - just display the text else echo $page['text']; } ?> </p>
That's all. Hope you find it useful in your own PHP coding project. :)
Back to studentship
Filed under:
Life and Leisure by
Hari
Posted on Fri, Sep 26, 2008 at 20:14 IST (last updated: Wed, Oct 29, 2008 @ 22:48 IST)
On a serious note, this is a chance for me to practice what I preach - that everybody should know the basics of Law - if only to know our rights and duties in a democratic society. The only thing about my course is that the college is quite distant from home and it takes a one-and-a-half hour train journey (apart from travel to and from the railway station) to get there. So nearly four hours a day is wasted on travel alone, but that's not too bad. The course looks to be interesting and becoming a practising advocate (or barrister, if you prefer) at the end of it has a lot of perks and benefits in society (along with the prestige). Screens of my blog software in development
Filed under:
My software by
Hari
Posted on Mon, Sep 22, 2008 at 21:54 IST (last updated: Wed, Oct 29, 2008 @ 22:45 IST)
) blog software in development if only to motivate myself to complete it in a reasonably short duration.
I'm finding that splitting the PHP code into many separate files (especially to separate forms from their actions, not using a templates system and avoiding predefined constants for every single message string is saving a lot of time.
Admin panel home
Blog configuration settings:
Categories management
Create/update a category
Delete category
Roadmap of my blogging system
Filed under:
My software by
Hari
Posted on Fri, Sep 19, 2008 at 14:30 IST (last updated: Fri, Sep 19, 2008 @ 14:30 IST)
- Single user, single blog engine. No complex user-access controls. Just one admin user for blog administration and content management
- Very lightweight. No usage of a client-server database engine or use of excessive PHP for processing data.
- Keep the SQL commands used simple, understandable and reliable.
- Categorization to be kept simple: single category per post and no nested categories. Suitable for most purposes
- Very basic blog search. Enough for most purposes.
- Customizable publish/draft mode for articles and ability to moderate or even turn off comments.
- Include RSS/Atom for posts as well as for comments.
- Pseudo-clean URL support. Not full-fledged "HTMLized" URLs like other blog platforms (that would add more code complexity and supporting at least 2 different types of URLs - one failsafe URL mechanism which doesn't require Apache's mod_rewrite.)
- Split most of the code into multiple files. Avoid complex coding in a single PHP file. Separate form content from action as much as possible.
- No usage of HTML template files for "skinning". Using a separate templating system makes coding easier, but it adds more overheads to the PHP engine.
- Easily navigable archives.
- Try to keep most of the static content in HTML to improve performance. Therefore no separate feature called "blogroll" just to implement what is basically a list of links that is infrequently updated.
- Keep the code-base modern and full in PHP 5. No backward compatibility with PHP 4. PHP 5 just has too many cool features to ignore.
- Try and keep the whole project (excluding images/database size) within 500 KB or at the most 700 KB.
Lunch breaks and effective working hours
Filed under:
People and society by
Hari
Posted on Wed, Sep 10, 2008 at 15:02 IST (last updated: Thu, Oct 30, 2008 @ 08:14 IST)