• Home
  • Shell
    • Emacs
    • Perl
    • screen
    • sed
  • Ubuntu
    • VNC
  • Web Development
    • Javascript
    • Joomla
    • MySQL
    • osTicket
  • Windows
    • Gimp

Posts tagged php

Usenet> Newznab backfilling

Jan31
2013
Written by Scott Rowley

I’ve recently been checking out newznab plus. I’ve found that while it’s nice as it slowly builds, it’s a bit annoying not having any older posts already loaded. Fortunately nn+ (nnp, newznab plus) comes with an option for backfilling. The instructions are useful but I’d like to expand on them to make it less of a hassle to update more than one particular group.

Please note that I’ve only been using nn+ for a few days now so there may indeed be easier ways to do things but this is the best way I’ve found so far. For example, I’m not exactly sure what the update_binaries_threaded.php file does but I don’t believe it does what I’m discussing here. I’m guessing from the “threaded” that it simply makes multiple threads of the same process to make the entire task faster.

The following is taken from http://newznab.readthedocs.org/en/latest/readme/#backfilling-groups

Backfilling Groups
Since most usenet providers have 800+ days of retention indexing all that information in one shot is not practical. Newznab provides a backfill feature that allow you to index past articles once your initial index has been built. To use the feature first set the back fill days setting in the group(s) to be backfilled to the number of day you wish to go back, making sure to set it higher than the number of days listed in the first post column. Once set run the backfill.php script in misc/update_scripts. Groups can be backfilled to a particular date using the script misc/update_scripts/backfill_date.php using the syntax:

php backfill_date.php 2011-05-15 alt.binaries.groupname.here

You can use the _threaded version of this script if on linux.

For more information on backfilling, see Update Scripts.

First off, what we need to do is to activate any groups we want. More than likely you’ve already done this. What you’ll want to do in order to backfill those groups is to change the ‘Backfill Days’ entry. This can be done through the webpage but if you are wanting to backfill all of them then this following command will make it much faster than manually clicking through a dozen or more groups.

You’ll need to be on the command line and then log into mysql

mysql -u root -p
Enter password:
mysql> use newznab; (or whatever your database name is)
mysql> update groups set backfill_target=365 where active=1;

You have now just changed all active groups to have a backfill of 365 days (1 year). Now we just need to run our backfill_date.php on each group. If we’ve got dozens of groups or more though this can be tedious to repeat over and over with each group. So instead we are going to get a list of all the active groups by running the following command:

mysql -u root -p newznab -e 'select name from groups where active=1;'> groups.txt

You can now go into the groups.txt file and remove and additional groups you want or just leave it intact if you want everything.

Finally we want to run the php backfill.php command to backfill each of our selected groups back 365 days (or whatever number you’ve selected, alternatively you can also skip updating the database with the amount of days to backfill and simply substitute the backfill_date.php as noted from the link.)

Normally this command would be run like so for a single group:

php backfill.php alt.binaries.groupname.here

But this is much too slow for multiple groups so we are going to use a ‘for’ function with our data from the groups.txt file we created.

for group in `cat groups.txt`; do php backfill.php $group; done

If you are like me and like to see your code before it runs then simply add an echo beforehand to view the results and then remove it when you are ready:

for group in `cat groups.txt`; do echo "php backfill.php $group"; done

The use of the backticks (`) around ‘cat groups.txt’ tells it to run the command in a subshell and then use the information from that back in the shell command.

Posted in BASH, PHP, Ubuntu - Tagged backfill, backfill days, BASH, for, groups, MySQL, newznab, newznab plus, nn+, nnp, update, usenet

osTicket> Show external ticket ID in browser title.

Aug13
2012
Written by Scott Rowley

 

At my full time job we often reference the ticket ID that we are working on in our daily log, notes or when just when referencing it from person to person. The following will allow for showing the external ticket ID in the browser title.

First we need a new function to reference, find the following in
include/class.ticket.php

/*============== Functions below do not require an instance of the class to be used. To call it use Ticket::function(params); ==================*/

And add the following right after it:

function getExtIdById($id){
$sql ='SELECT ticketID FROM '.TICKET_TABLE.' ticket WHERE ticket_id='.db_input($id);
$res=db_query($sql);
if($res && db_num_rows($res))
list($extid)=db_fetch_row($res);
return $extid;
}

Now open up
include/staff/header.inc.php and add the following just after your <title> tag:

<?if(Ticket::getExtIdById($id)){ echo Ticket::getExtIdById($id)." - "; }?>

Update!
There are a couple of pages you may be on (like “My Preferences”) where the ticket class is not loaded. In order to make sure it’s loaded for use you can added the following just before the title tag:

require_once('../include/class.ticket.php');
Posted in MySQL, osTicket, PHP - Tagged browser, class, external id, function, internal id, osTicket, reference, title

Web Dev> pChart WriteValues text color

Jun07
2012
Written by Scott Rowley

Just a quick post since I started toying around with pChart 2.x to add emailed reports to my osTickets Reports MOD. This took me awhile to locate and that was including 20 minutes of googling failing me.

In order to change the font color of the WriteValues (the values that show up over your generated charts). You can modify the numbers in the following file
pChart/class/pRadar.class.php

$ValueR = isset($Format["ValueR"]) ? $Format["ValueR"] : 0;
$ValueG = isset($Format["ValueG"]) ? $Format["ValueG"] : 0;
$ValueB = isset($Format["ValueB"]) ? $Format["ValueB"] : 0;

Setting the above to 0’s instead of 255 will change the text from white to an easier to read black.

Posted in PHP, Web Development - Tagged Charts, Format, pChart, ValueB, ValueG, ValueR, WriteValues

Web Dev> Obtaining Google PageRank

Jun06
2012
Written by Scott Rowley

As a part of Search Engine Optimization (SEO) you may want to be aware of your websites (or clients websites) page rank on Google. After some researching I’ve found the following solutions to be best. I’ll be presenting a few options here, first we’ll cover how to look it up on prchecker.info. Second we’ll be covering how to look up the page rank using a perl script and finally we’ll cover how to look up your page rank with the perl script and update a mysql database with the information (for long term tracking and/or tracking multiple websites.)
READ MORE »

Posted in MySQL, Perl, PHP, SEO, Web Development - Tagged database, google, MySQL, page, page rank, Perl, prchecker.info, rank, script, search engine optimizaiton, SEO

Web Dev> Handling dynamically created checkboxes

May02
2012
Written by Scott Rowley

Ok, so let’s say I have a list of users in a database. I want to get that list out on the screen and allow someone to be able to use checkboxes to do something with each of those users. In this example we’re going to say we are deleting any users that have been checked. If you are not already familiar with building dynamic output from mysql then I suggest you first read over Web Dev> Populate PHP/HTML table from MySQL database

First we’ll build our form to show our users, in this example I’m actually building my list of users from a query to a mail server which gets returned to me first as a string. I need to change this into an array so I’m going to use explode(). I’ll go through this all step by step so it’s easy to follow along and you can skip whatever parts you feel you are already familiar with.

So lets say the mail server returns this string to me of users:

$members_string = 'Bruce Chuck Jackie Jet';
echo "Members string is '$members_string'";

Which gives us an output of

Members string is 'Bruce Chuck Jackie Jet'

Since I want to loop through each of these members I need to first create an array that I can loop through, this is where explode() comes in.

// Members are separated by spaces, so explode on spaces
$members = explode(' ',$members_string);

READ MORE »

Posted in PHP, Web Development - Tagged checkbox, dev, dynamic, form, web, web dev, Web Development

Web Dev> PHP function, check if a MySQL table exists

May01
2012
Written by Scott Rowley

Note: This is NOT original sudobash.net code. This has been copied over from ElectricToolBox.com, full credit goes to him/her (I couldn’t find a name anywhere).

The PHP function below gets passed in a tablename and an optional database name. If the database name is not passed in then it retrieves it using the MySQL function SELECT DATABASE(). It then queries the MySQL information schema to see if the table exists and then returns either true or false.

function table_exists($tablename, $database = false) {
if(!$database) {
$res = mysql_query("SELECT DATABASE()");
$database = mysql_result($res, 0);
}
$res = mysql_query("
SELECT COUNT(*) AS count
FROM information_schema.tables
WHERE table_schema = '$database'
AND table_name = '$tablename'
");
return mysql_result($res, 0) == 1;
}

The PHP MySQL functions are used in the above example. A database connection is assumed and there is no error checking, but you can modify it to utilise whatever database library / abstraction layer you are using in your project and improve how you see fit.

To use the function you’d do something like this:

if(table_exists('my_table_name')) {
// do something
}
else {
// do something else
}

and if you wanted to specify the database name as well (perhaps you are needing to query if the table exists in multiple databases other than the one you are currently connected to), you’d do this:

if(table_exists('my_table_name', 'my_database_name')) {
// do something
}
else {
// do something else
}
Posted in MySQL, PHP, Web Development - Tagged check, database, dev, exists, function, MySQL, table, web, Web Development

WebDev> Fixing Warning: “Headers already sent” & “Cannot modify header information”

Mar24
2012
Written by Scott Rowley

Eventually in your web development you may run into one of these annoying errors. What it typically means is that your browser is being sent some HTML before the PHP command header() and it’s causing your issue.

Unfortunately there is no easy way to go about troubleshooting this other than following the logic through your code, hopefully you’ve saved & tested recently and have a fairly short code to go troubleshooting with. In video games I learned early on to “Save early, save often”. I’ve since modified that to my programming so that I remember to save early, save often but also “Test early, test often”. Make little changes, then you know how much you need to go back and troubleshoot when there is an error. Anyway, another less known cause of this issue is that you’ve got the dos character ^M inserted in your code. This recently happened to me when I used FTP to download a website and then uploaded it somewhere else. Somewhere along the line my windows PC decided my perfectly fine files should have some ^M inserted into some of the files. As a result I got the “Headers already sent” error.

I’d run into the error before but I knew that I hadn’t introduced any new code so I knew it couldn’t be any html being sent before the header() function. After much googling and “facedesk”‘ing I finally found that the dos character could also cause this error. After a bit more googling I found that the easiest way to get rid of this is to simply run the following command and it will easily and quickly remove all of the dos characters (^M).

dos2unix your_messed_up_file.php

I ran this command on the file and then tried my test again and just like that I was back to normal again 🙂

Posted in Web Development - Tagged already, cannot, development, dos2unix, fix, fixed, fixing, headers, information, modify, save, sent, test, troubleshoot, warning, web

WebDev> Alternate table row color with PHP & CSS

Mar19
2012
Written by Scott Rowley
<style>
tr.odd {
background: #d0d0d0;
}
</style>
echo <?php '<tr'.(($c = !$c)?' class="odd"':' class="even"').'>'; ?>
Posted in PHP, Web Development - Tagged css, echo, row, script, table

WebDev> Allow PHP in WordPress Widgets

Jan26
2012
Written by Scott Rowley

The following will allow for you to post PHP in your widgets:

Place in your functions.php file
Appearance> Editor> Theme Functions (functions.php)

// Allow PHP in Widgets
add_filter('widget_text', 'php_text', 99);
function php_text($text) {
if (strpos($text, '<' . '?') !== false) {
ob_start();
eval('?' . '>' . $text);
$text = ob_get_contents();
ob_end_clean();
}
return $text;
}

Now you can place php code so long as its within its <?php and ?> tags.
Credit

Posted in Web Development - Tagged allow, functions, theme, widget, wordpress

Web Dev> Select first n words of a sentence

Jan16
2012
Written by Scott Rowley

Useful for giving a teaser of a post and then including … on the end followed by “Read More”.

$sentence = "This is my sentence, there are many like it but this one is mine. What do you think of it?";
$n = 10; // Customize to however many words you want to actually show
$teaser = implode(' ', array_slice(explode(' ', $sentence), 0, $n));
echo $teaser."…READ MORE

Which should result in:
This is my sentence, there are many like it but…READ MORE

Posted in PHP, Web Development - Tagged array_slice, customize, echo, explode, implode, n, post, read more, sentence, teaser
« Older Entries

Corrections? Questions? Comments?

Find an error?
Everything work out great for you?
Have some feedback?
Like to see something added to the article?

PLEASE leave us a comment after the article and let us know how we are doing, or if something needs corrected, improved or clarified.

Thank you!
- The Management

Advertisement

Sudo Bash
By Geeks - For Geeks

Back to Top