PHPBuilder - OwnLinkSite Automatic link generator for adult sites



RSS Twitter
Snippets Html

OwnLinkSite Automatic link generator for adult sites

by: Jim
|
February 18, 2004

Version: 2.1

Type: Full Script

Category: HTML

License: Other

Description: The OwnLinkSite link engine consists of a database and some php-based scripts. The user gets access to hundreds of thousands of links to adult pick- and video- sites. Free scripts and templates make both design and daily updating a breeze. The system is particularly useful for attracting as many readers as possible. OwnLinkSite.com has a very extensive tutorial explaining how to set up use the system, and how to get a high rating by Google.</



<?  //  pagetransform.php
/***********************************************************************
*
*    ***      pagetransform.php PROGRAM LISTING      ***
*    ***  How to use is outlined at ownlinksite.com ***
*
* 27.12.2002 V 1.0 Beta
* 12.04.2003 V 1.1 Stable
* 19.07.2003 V 2.0 Major update
* 21.09.2003 V 2.1 Some small bug fixes
*
* Place the code in a sub-directory called ownlinksite and name it
* pagetransform.php.
* Also, put links.php and linkcollector.php in the same directory.
*
* This program transfers a template link page into an actual, working
* php-based link page, as described in the tutorial how_to.php
*
* All rights reserverd J.P.C.D.S., Inc.
* 
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
* 
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
***********************************************************************/

class pagetransform  {

    // URL to where the OwnLinkSite database resides:
    var $_url_linkbase = 'ownlinksite.com/pagetransform_base.php';

    var $_msg_arr;  // Errors, warnings and messages created in this
                    // program, to be displayed to user

function pagetransform()  {
/***********************************************************************
* Constructor. When the object is created, do the whole job.
***********************************************************************/

}

function check_dirs()  {
/***********************************************************************
* Creates directories pagedata,links and picks if they do not exist already
***********************************************************************/

    $dirs = array('pagedata','links','picks');

    foreach($dirs as $directory)  {
        if(!is_dir($directory)) { // Does not exist, create it
            if(!mkdir($directory, 0777))  { // Could not create, give warning
                $this->_msg_arr[] = "<b>Warning:</b>Tried to create directory 
                                    <b>$directory</b>, but did not succseed.
                                    Try creating it manually or change the permissions.
                                    This problem is explained in greater detail
                                    in the tutoril in ownlinksite.com";
        } else {
            $this->_msg_arr[] = "<b>Info:</b>Directory $directory created successfully";
            }
    } else {
        $this->_msg_arr[] = "<b>Info:</b>Directory $directory was there already, not created now";
        }
    }
}

function binary_read($url)  {
/***********************************************************************
* Uses the binary reader fread to grab and return web content or file
***********************************************************************/
    $x = '';
    if($fp = @fopen($url,"rb"))  {
        while(!feof($fp)) {
            $x.= fread($fp,1024);  // Read 1024 bytes at a time
        }
        fclose($fp);
        return $x;  // Success, return result
    } else {
        $this->_msg_arr[] = "<b>Warning:</b>Could not read $url";
        return 0;  // Could not open, return false
    }
}

function date_options()  {  
/***********************************************************************
* All different date formats the user may choose from.
* Returns an array with all formats.
***********************************************************************/
    return array('d-m','m-d','d-m-Y','M d.','D m-d','l m-d','D m-d-y',
                'D m-d-Y','D','l');
}

function date_dropdown()  {
/***********************************************************************
* Puts the dates listed in function date_options() into a dropdown
***********************************************************************/
    $date_options = $this->date_options();
    $x = '<select size="1" name="date_format">';
    foreach($date_options as $date_format)  {
        $x .= '<option value="'.$date_format.'">'.
              date($date_format, time()).'</option>';
    }
    $x .= '</select></p>';
    return $x;
}


function show_input_form()  {
/***********************************************************************
* Prints the form used to insert the template-HTML to be transformed
***********************************************************************/
    $x  = '<form method="POST" action="pagetransform.php">';
    
    $x .= '&nbsp;<p><b><font face="Verdana">'.
          'If you use dates on your page, select preferred format: '. $this->date_dropdown();
    $x .= 'If you want the finished page to be saved automatically,<br>please write its name here
          <input type="text" name="file_name" size="20" value="index.php">';
    $x .= '</p> <br>Paste your template HTML into the text area below&nbsp; ';
    if(isset($_GET['blocker'])) $x .= '<input type="hidden" name="blocker" value="'.$_GET['blocker'].'">';
    $x .= '&nbsp;<input type="submit" value="Submit">';
    $x .= '<p><textarea rows="16" name="page" cols="60"></textarea>';
    $x .= '</font></b></p></form>';
    
    return $x;
}

function show_code($text)  {
/***********************************************************************
* Transforms the text to make it possible to show it via browser
* Tags are replaced by their specialchrs equivalents, and new lines 
* like \n are replaced by <br>
***********************************************************************/
    $table_start = '<br></div><table width=100% border=1 cellpadding=0 cellspacing=0>
                    <tr><td bgcolor="#FFFFCC">';
    $table_stop  = '</br></td></tr></table>';

    return $table_start.nl2br(htmlspecialchars($text)).$table_stop;
}

function make_post_request($post_array) {
/***********************************************************************
//* 28.09.2003 
* Makes a POST request to the main OwnLinkSite server
* The main server then returns the complete php code.
***********************************************************************/
    $url = $this->_url_linkbase;
    $url = eregi_replace("^http://", "", $url);
    
//  Separate into Host and URI
    $host = substr($url, 0, strpos($url, "/"));
    $uri  = strstr($url, "/");

//  Form up the request body
    $post_vars = "";
    while (list($key, $val) = each($post_array)) {
      if ($post_vars) $post_vars.= "&";
      $post_vars.= $key."=".urlencode($val);
    }

    //  Text used in the request header:
    $header_text =
      "POST $uri HTTP/1.0\n".
      "Host: $host\n".
      "Content-Type: application/x-www-form-urlencoded\n".
      "Content-Length: ".strlen($post_vars)."\n\n".
      "$post_vars\n";

    //  Open the connection to the host
    $socket = fsockopen($host, 80);
    $x = '';
    fputs($socket, $header_text);
    while (!feof($socket)) {
        $x .= fgets($socket, 1024);
    }
    return $x;
}

function get_quasi_xml($x,$tag)  {
/***********************************************************************
* Some parameters return from the OwnLinkSite server as text between 
* tag-like brackets. This function isolates text of interest by
* stripping out everything between <tag> and </tag> in the text x 
***********************************************************************/
    return substr(strstr(substr($x, 0, strpos($x, "</$tag>")),
          "<$tag>"), strlen("<$tag>"));
}

function parameters_to_save()  {
/***********************************************************************
* Lists all the constants and arrays to be saved on the client's 
* harddisk (transferred from pagetransform_base.php) on the OwnLinkSite
* server. All arrays are stored serialized.
*
* n_days          = Number of days categories are shown from.
* date_format    = The date format used for all dates on page
* pick_b          = How broad the pix shall be on display, in pixels
* pick_h          = How tall the pixs are
* links_each_cat  = Array with number of links in each category 
* picks_each_cat    = Array with mumber of pix in each category. Note it is the
*                  displayed number which is stored, not the (much higher)
*                  number of pick links passed from main server.
* var            = Array containing all categories in use, like url, short, ..
* bookmarks      = Used as bookmark to know where to select records
*                  next time.
***********************************************************************/
    return array('n_days_links','n_days_picks',
                'date_format','pick_b','pick_h','user',
                'links_each_cat','picks_each_cat','var','bookmarks');
}

function save_to_file($x, $file)  {
/***********************************************************************
//* 20.09.2003
* Saves $x to file $file
***********************************************************************/
    if($fp = fopen($file, 'w'))  {
        fwrite($fp, $x);
        fclose($fp);
        return 1;
    } else {
        $dir_info = '';
        if(strlen(trim(eregi_replace("/[^/]*$",'',$file))) > 0)
            $dir_info = 'for directory '.eregi_replace("/[^/]*$",'',$file);
        $this->_msg_arr[] = "<b>Warning:</b>Could not open file $file and save
                            - please check access permissions ".$dir_info;
        return 0;
    }
}

function save_parameters($x)  {
/***********************************************************************
* Saves those parameters present in $x
***********************************************************************/
    foreach($this->parameters_to_save() as $par_name)  {
        $parameter = $this->get_quasi_xml($x,$par_name);
        if(strlen($parameter)!=0 && strlen($parameter) < strlen($x))  {
            $this->save_to_file($parameter,"pagedata/$par_name.txt");
        //  print "<br>Saved $par_name";
        }
    }
}

function messages_presentable()  {
/***********************************************************************
* Returns the messages in a neat table
***********************************************************************/

    $x  = '<div align="center">
          <table border="1" cellpadding="0" cellspacing="0" width="80%">
          <tr><td bgcolor="#FF00FF" align="center"><h2>Messages from pagetransform.php: </h2>
          </td></tr><tr><td>';

    if(is_array($this->_msg_arr))  { // Put some colors on the messages
        $x .= str_replace('Warning:','<font color="#0000FF">Warning:</font>',
              str_replace('Error:','<font color="#FF0000">Error:</font>',
              str_replace('</b>','</b><br>',implode('<br>',$this->_msg_arr))))
            .'</td></tr>';
    } else {
        $x .= '<b>None.</b> Everything went well</td></tr>';
    }
    $x .= '</table></div>';
    if(is_array($this->_msg_arr))  {
        return $x;
    } else {
        return 0;
    }
}

function transform_and_save()  {
/***********************************************************************
* Transfers the page and saves the result
***********************************************************************/

    $this->check_dirs();  // Create the directories pagedata, links, picks
    
    $x  = '<table width="100%" border="0" cellpadding="0" cellspacing="0">';
    $x .= '<tr><td bgcolor="#FFCC33" align="center"><br><h2>';
    $x .= '<font face="Verdana">Transforming the template to php-code</font>';
    $x .= '</h2></td></tr>';
  
    if(!isset($_POST['page'])) {  // The form not shown alrady, do it now
        $x .= '<tr><td align="center">'.$this->show_input_form().'</td></tr>';
    } else {
        // Date format and day of interest is saved directly
        $this->save_to_file($_POST['date_format'],'pagedata/date_format.txt');
        $this->save_to_file(0,'pagedata/day_of_interest.txt');  // Generally today
        
        $page  = stripslashes($this->make_post_request($_POST)); 
        
        
        $show=stripslashes($this->get_quasi_xml($page,'page'));

        if(strlen($_POST['file_name']) > 2)  {  // The user request auomatically saving the page
            if(!$this->save_to_file($show,'../'.$_POST['file_name']))  {  // Could not save
                $x .= '<tr><td align="left"><br><b><h3><font face="Verdana">'.
                      "<h2>Unable to save the file utomatically!</h2>
                      Please do it manually by saving this code
                      in the main directory and call it <i>$_POST[file_name]</i>
                      </font></h3></b>";
                $x .= $this->show_code($show);
            } else {

                $x .= '<tr><td align="left"><br><b><h3><font face="Verdana">';
                $x .= "The transformed file has been saved as $_POST[file_name]</h3>";
                $x .= "<b>Please run <a href=\"linkcollector.php\" target=\"_blank\">linkcollector.php</a>
                          to collect the first links and picks,
                      and have a look at your page!</b><br><br>";
            }
  
        } else {
      
            $x .= '<tr><td align="left"><br><b><h3><font face="Verdana">Put this 
                  code in the main directory and call it <i>index.php</i>
                  or whatever:</font></h3></b>';
            $x .= $this->show_code($show);            
        }

        $x .= '</td></tr>';
        $this->save_parameters($page); 
    }
    $x .= '<tr><td align="center"><b><h3><font face="Verdana">'.
          '<a href="index.php">home</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <a href="pagetransform.php">reset</a>'.
          '</font></h3></b></td></tr>';
    $x .= '</table>';
    
    if($this->messages_presentable()) $x .= $this->messages_presentable(); // Messages from this program
    if(isset($_POST['page'])) {
        if($this->get_quasi_xml($page,'message')) {
            $x .= $this->get_quasi_xml($page,'message');                  // Messages from server
        }
    }
    return $x;
}
} // END CLASS pagetransform.php



/*BLOCKER*/
    // Uncomment the if-line below to protect pagetransform.php from un-authorized use
    // After un-commenting, the program must be called with the blocker-parameter
    // (in addition to any other arguments to be passed) like so:
    // http://your-site.com/ownlinksite/pagetransform.php?blocker=j9n8n72
//    if($blocker != 'j9n8n72') exit();


    // Do the pagetransform
    $pagetransform = new pagetransform();
    print $pagetransform->transform_and_save();
?>





<?  //  linkcollector.php  
/***********************************************************************
*
*    ***      linkcollector.php PROGRAM LISTING      ***
*    ***  How to use is outlined at ownlinksite.com ***
*
* 17.01.2002 V 1.0 Beta
* 22.04.2003 V 1.1 Stable
* 13.07.2003 V 2.0 Major update
* 14.09.2003 V 2.1 Some small bug fixes
*
* Place the code in a sub-directory called ownlinksite and name it
* linkcollector.php.
* Also, put pagetransform.php and links.php in the same directory.
*
* This program runs as a regular (typically daily) cronjob on 
* the client's server.
*
* It communicates with pagetransform.php on the OwnLinkSite server 
* and receives records which it unzips, unserializes and places in the
* directory links.
* 
* Also, this program receives links to picks, downloads one pick pr. page,
* and places them in the directpory called picks.
*
* All rights reserverd J.P.C.D.S., Inc.
* 
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
* 
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
***********************************************************************/

class linkcollector {

    // URL to where the OwnLinkSite database resides:
    var $_url_linkbase = 'http://ownlinksite.com/linkbase.php';
    var $_time_limit  = 10; // How many seconds this program should run before
                            // it times out. Consider increasing this value if
                            // you have many picks or if your server has a very
                            // slow internet connection
    
    var $_url;      // The url used to request links from the OwnLinkSite
                    // database, complete with all path and query
    var $_get_arr;  // Array containing the different GET-parameters
                    // included behind ? in the url
    var $_result;    // Everything coming back from the OwnLinkSite server
    var $_result_arr; // Array with the different parts of $_result
                    // split into each of the parameters listed in
                    // function create_result_arr
                    // Gets value false if no array could be created
    var $_day_index;  // The letter indicting which day the results should
                    // be stored as (a,b,c.. See function day_index
    var $_msg_arr;  // Errors, warnings and messages created in this
                    // program, to be displayed to user
    var $_linkcoll_stopped = false; // Becomes true if erroe made it necessary to stop
                    
function linkcollector()  {
/***********************************************************************
* Constructor. When the object is created, do the whole job.
***********************************************************************/

    set_time_limit($this->_time_limit);
    $this->create_timestamp_if_missing();
}

function create_timestamp_if_missing()  {
/***********************************************************************
* If a timestamp_start does not exist, it creates one now
* This function should only be relevant first time linkcollector is run
***********************************************************************/
    $file = 'pagedata/timestamp_start.txt';
    if(!is_file($file) || $this->binary_read($file) < 100)
        $this->save_to_file(time(), $file);
}

function get_arr()  { 
/***********************************************************************
* Names of all different data to be passed in the URL 
* The onces which are arrays are preceeded with a_ to destiguish them
************************************************************************/
    $x[] = 'user';              // The user name, from file
    $x[] = 'password';          // Password, from either user input or file
    $x[] = 'timestamp_start';  // Time when pagetransform was run, from file
    $x[] = 'day_of_interest';  // Normally 0, meaning 0 days ago (today!)
    $x[] = 'n_days_links';        // Total number of days of interest for each link category
    $x[] = 'n_days_picks';        // Same for picks (if the page has picks!)
    $x[] = 'var';              // Which data to retrieve for each text link (ex. url, description..)
    $x[] = 'links_each_cat';    // Number of links in each category, array
    $x[] = 'picks_each_cat';    // Number of picks in each category
    $x[] = 'bookmarks';        // Bookmarks telling the database where it finished
                                // retrieving links for each category last time

    // These data are not required by linkbase, but are used by linkcollector
    $x[] = 'pick_b';            // Desired pick sizes
    $x[] = 'pick_h';

    return $x;
    }

function result_arr()  {
/***********************************************************************
* Names of all data which may come in return from the database
************************************************************************/

    $x[] = 'links';      // The text links (URL, short descripive text, 
                        // long descriptive text, which category it belongs to,
                        // number of picks on the page it points to
    $x[] = 'picks';      // Similar as links, but for pick links
    $x[] = 'bookmarks';  // See above
    $x[] = 'compress';  // Logical, tells whether links and picks arrive compressed
    $x[] = 'password';
    $x[] = 'user';
    $x[] = 'timestamp_start'; // Timestamp first time linkcollector was run
    $x[] = 'message';    // Messages generated by the OwnLinkSite server
    
    return $x;
}

function remove_behind_first($x, $x2)  {
/***********************************************************************
* Uses fast functions (no slow ereg-type pattern matching) to delete
* everything including and behind $x2
***********************************************************************/
// If $x2 occurs in $x: Strip. Else, return as-is
    if (substr_count($x, $x2)) return substr($x, 0, strpos($x, $x2));
    else                      return $x;
}

function remove_before_first($x, $x1)  {
/**********************************************************************
* Uses fast functions (no slow ereg-type pattern matching) to delete
* everything including and in front of $x1
**********************************************************************/
// If $x1 occurs in $x: Strip. Else, return as-is
    if (substr_count($x, $x1))  return substr(strstr($x, $x1), strlen($x1));
else                        return $x;
}

function binary_read($url)  {
/***********************************************************************
* Uses the binary reader fread to grab and return web content or file
***********************************************************************/
    $x = '';
    if($fp = fopen($url,"rb"))  {
        while(!feof($fp)) {
            $x.= fread($fp,1024);  // Read 1024 bytes at a time
        }
        fclose($fp);
        return $x;  // Success, return result
    } else {
        return 0;  // Could not open, return false
    }
}

function create_url()  {
/***********************************************************************
* Creates the URL with all necesary GET-variables for retrieving data from
* server. Terminates program if any data is unavailable
***********************************************************************/

    $variable_names = $this->get_arr();  // all variables to be included in URL

    // Read all variables from file and put them into a global array
    foreach($variable_names as $name)  {
        $file = "pagedata/$name.txt";
        
        if(file_exists($file))  {
            $value = trim($this->binary_read($file));
            $this->_get_arr[$name] = $value;
        } else {
            $this->_msg_arr[] = "<b>Warning:</b> Could not find file $file";
        }
    }
    
    // No point continuing if lots of data are missing
    if (count($this->_get_arr) < 2)  {
    
        $this->_msg_arr[] = "<b>Error:</b> Link collection aborted. Reason:
                            Missing necessary data in directory 
                            ownlinksite/pagedata. Please check the tutorial at
                            <a href=\"http://ownlinksite.com\">ownlinksite.com</a>
                            for details on directory structure.";
        $this->_linkcoll_stopped = true;
        return false;
    }

    // If the user has included a password in the call to this program, let it
    // take precedence over the (older password) stored on file
    if (isset($_GET['password'])) $this->_get_arr['password'] = $_GET['password'];
    
    // Default day of interest is 0 (today), not stored on file
    if (!isset($this->_get_arr['day_of_interest'])) $this->_get_arr['day_of_interest'] = 0;
    
    // Create the complete url to fetch links
    $this->_url = $this->_url_linkbase . '?';
    foreach($this->_get_arr as $key=>$value)  {
        $this->_url .= $key . '=' . $value . '&';
    }

    return $this->_url;
}

function download_everything()  {
/***********************************************************************
* Get everything from the OwnLinkSite server
***********************************************************************/
    $t1 = time();
    //print $this->create_url();
    
    if($result = $this->binary_read($this->create_url()))  {
        if(strlen($result) > 100)  { // Success
            $this->_msg_arr[] =  '<b>Info:</b> Collecting links from OwnLinkSite
                                  was done in ' . (time()-$t1) . ' sec.';
            return $this->_result = $result;
        } else {
            $this->_msg_arr[] =  '<b>Error:</b> Collecting links from OwnLinkSite
                                  was not successful. Contact with server was
                                  established, but the response text was too short.
                                  It contained this: '.nl2br(htmlspecialchars($result));
            return 0;
        }
    } else {
        $this->_msg_arr[] =  '<b>Error:</b> Could not establish contact with
                            the OwnLinkSite server using url '.$this->_url;
        return false;
    }
}

function get_quasi_xml($x,$tag)  {
/***********************************************************************
* Parameters return from the OwnLinkSite server as text between 
* tag-like brackets. This function isolates text of interest by
* stripping out everything between <tag> and </tag> in the text x 
***********************************************************************/
    $result=substr(strstr(substr($x, 0, strpos($x, "</$tag>")),
          "<$tag>"), strlen("<$tag>"));
    if(strlen($result)) return $result; // Some contents found
    else                return 0;
}

function day_index($timestamp_start,$n_days,$day_of_interest=0)  {
/***********************************************************************
* Returns the day index for for the day of interest
* Ex.: a for day 0, b for day 1. If 3 days are included, it starts on a
*      again on the 4. day
*
* $days_from_start = The timestamp (in seconds) when the client started
*                    using ownlinksite.
* $n_days          = The number of days the client has information from 
*                  = on his web. (ex.: Every second day over 6 days is 3)
* $day_of_interest  = Number of days since the day of intreest (ex. 0=today,
*                    1 = yesterday)
***********************************************************************/

    // 26 days possible, but use only $n_days of them. First time, start with a.
    $indexes = explode(',','a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z');
    
    // Number of days from start to day of interest, rounded off up or down to nearest whole day
    $days_from_start = (int)((time()-$timestamp_start)/(3600*24) + .5) - $day_of_interest;
    
    // Go up or down n_days at a time until the day is within acceptable limits
    while ($days_from_start < 0)          {
        $days_from_start += $n_days;
    }
    while ($days_from_start > $n_days-1)  {
        $days_from_start -= $n_days;
    }
    return $indexes[$days_from_start];
}

function create_result_array()  {
/***********************************************************************
* Strip out the different parts of the result
***********************************************************************/

    if(!$this->download_everything()) return false; // Stop if no downloading success
    
    $variable_names = $this->result_arr();
    
    foreach($variable_names as $name) {
        if(substr_count($this->_result, $name))  { // The parameter arrived
            if($variable = $this->get_quasi_xml($this->_result,$name)) { // Not empty
                $this->_result_arr[$name] = $variable;
            }
        }
    }
}

function save_to_file($x, $file)  {
/***********************************************************************
* Saves $x to file $file
***********************************************************************/
    if($fp = fopen($file, 'w'))  {
        fwrite($fp, $x);
        fclose($fp);
        return 1;
    } else {
        $dir_info = '';
        if(strlen(trim(eregi_replace("/[^/]*$",'',$file))) > 0)
            $dir_info = 'for directory '.eregi_replace("/[^/]*$",'',$file);
        $this->_msg_arr[] = "<b>Warning:</b>Could not open file $file and save
                            - please check access permissions ".$dir_info;        return 0;
    }
}
function uncomp_unser_each_row($x)  {
/***********************************************************************
* Avoid extensive memory usage by un-compressing each category separately
***********************************************************************/
    $x = unserialize($x);
    if(!is_array($x)) return $x;  
    foreach ($x as $key => $value)  {
        $x[$key] = unserialize(gzuncompress($value));  // Had to add unserialize here!
    }
    return $x;
}
function uncompress_each_row($x)  {
/***********************************************************************
* Avoid extensive memory usage by un-compressing each category separately
***********************************************************************/
    //print "<br>x=$x";
    if(strlen($x) < 1) return $x;
    $x = unserialize($x);
    foreach ($x as $key => $value)  {
        $x[$key] = gzuncompress($value);
    }
    return $x;
}

function save_x_files($x)  {
/***********************************************************************
* Creates one file with text link data for each category for this day
***********************************************************************/
    if(!is_array($x)) return;
    // Use the day index to get a unique file name for this day
    foreach($x as $id_category => $values)  {
        $this->save_to_file($values, "links/x_$id_category"."_".$this->_day_index.".txt");
    }
}

function save_picks($y)  {
/***********************************************************************
* Download and save the picks, and save the URLs they poin to
* as well as descriptive text (to assist Google and the links
* in determining content)
***********************************************************************/

    if(!is_array($y)) return;  

    $picks_each_cat = unserialize($this->_get_arr['picks_each_cat']);
    foreach($y as $id_category => $value1)  {
        $j = 0;
        foreach($value1 as $i => $value2)  {
            $pick_url = $value2[2];
            if(isset($value2[3])) $im_url = $value2[3];
            else                  $im_url = '';
            
            $getpick = new getpick($pick_url, $im_url);
            
            $getpick->_new_w = $this->_get_arr['pick_b']; // Preferred pick size
            $getpick->_new_h = $this->_get_arr['pick_h'];
            
            if($getpick->download())  {

                // Put all picks in one directory, with y_ id_category, a running number, day index and .jpg
                $getpick->save_pick($adr="picks/y_$id_category"."_".$j."_$this->_day_index.jpg");
                if($getpick->messages_to_html()) $this->_msg_arr[] =  '<b>Info:</b>'.$getpick->messages_to_html();
                unset($getpick);  // Finished downloading, free memory
                
                $y_used[$id_category][$j][0] = $value2[0]; // Page URL
                $y_used[$id_category][$j][1] = 'ownlinksite/'.$adr; // Path to pick                
                $y_used[$id_category][$j][2] = $value2[1]; // Short
                $j++;                
                // Break out of this category if enough picks have been downloaded
                
                if($j >= $picks_each_cat[$id_category])  break(1);
            }
        }
    }
    // Go through all downloads to find out if enough were downloaded
    foreach($y as $id_category => $value1)  {
        if(!isset($y_used[$id_category]))  { // No picks downloaded!
            $this->_msg_arr[] =  "<b>Warning:</b>Did not manage to download any pics in category $id_category.
                                  Expect some of the old picks to be shown multiple times to
                                  account for that";
        } elseif(count($y_used[$id_category]) < $picks_each_cat[$id_category]) {
            $this->_msg_arr[] =  "<b>Warning:</b>Tried to download ".
                                  $picks_each_cat[$id_category].
                                  " in category $id_category, but only managed to download ".
                                  count($y_used[$id_category]).
                                  " Expect some of the old picks to be shown multiple times to
                                  account for that";
        }
    }
    
    // Save the links which were used. Serialize each.
    if(isset($y_used))  {
        foreach($y_used as $id_category => $values)  {
            $this->save_to_file(serialize($values), "links/y_$id_category".
                                "_".$this->_day_index.".txt");
        }
    }
}

function messages_presentable()  {
/***********************************************************************
* Returns the messages in a neat table
***********************************************************************/

    $x  = '<div align="center">
          <table border="1" cellpadding="0" cellspacing="0" width="80%">
          <tr><td bgcolor="#FF00FF" align="center"><h2>Messages from linkcollector.php: </h2>
          </td></tr><tr><td>';

    if(is_array($this->_msg_arr))  { // Put some colors on the messages
        $x .= str_replace('Warning:','<font color="#0000FF">Warning:</font>',
              str_replace('Error:','<font color="#FF0000">Error:</font>',
              str_replace('</b>','</b><br>',implode('<br>',$this->_msg_arr))))
            .'</td></tr>';
    } else {
        $x .= '<b>None.</b> Everything went well</td></tr>';
    }
    $x .= '</table></div>';
    if(is_array($this->_msg_arr))  {
        return $x;
    } else {
        return false;
    }
}

function save_everything()  {
/***********************************************************************
* Saves all returned variables to file
***********************************************************************/

    // If downloading from server has not been done, do it now
    if(!is_array($this->_result_arr) && !$this->_linkcoll_stopped) $this->create_result_array(); 
    if($this->_linkcoll_stopped)  {  // Could not create relevant URL
        print $this->messages_presentable();
        exit();
    }

    // Make the day index, to be used as part of file names
    $n_days = max($this->_get_arr['n_days_links'],$this->_get_arr['n_days_picks']);
    $this->_day_index = $this->day_index($this->_get_arr['timestamp_start'],$n_days,$day_of_interest=0);
    
    // If we have links, save them in one file pr. category
    if($this->_get_arr['n_days_links']) $this->save_x_files($this->uncompress_each_row($this->_result_arr['links']));
    $name = 'bookmarks';
    $this->save_to_file($this->_result_arr[$name],'pagedata/'.$name.'.txt');  // Save the bookmarks serialized
    $name = 'password';
    $this->save_to_file($this->_result_arr[$name],'pagedata/'.$name.'.txt');  // Save the password
    $name = 'user';
    $this->save_to_file($this->_result_arr[$name],'pagedata/'.$name.'.txt');  // Save the user

    if($this->_get_arr['n_days_picks']) $this->save_picks($this->uncomp_unser_each_row($this->_result_arr['picks']));
}
}  // END CLASS linkcollector.php

class getpick  {
/***********************************************************************
*
*    ***  getpick.php PROGRAM LISTING  ***
*
* 17.01.2002 V 1.0 Beta
* 22.04.2003 V 1.1 Stable
* 13.07.2003 V 2.0 Major update
* 14.09.2003 V 2.1 Some small bug fixes
* 22.12.2003 V 3.0 Major update for increased flexibility
*
* When the object is instantiated, an image is downloaded and placed in 
* $_img.
* Of the 2 arguments passed to the constructor, the first is asumed to be
* url to  pick, the second (if it exists) is to the large image.
*
* Best result if the GD-librry is installed (likely for php 4.3.0 or later)
* The object checks whether the GD-library is installed. If it is, it uses
* it. If not, it uses workrounds to get a pick, but it is unable to re-
* format it to the desired size, so expect the picks to be of a different
* size than requested.
*
* All rights reserverd J.P.C.D.S., Inc.
* 
* This program belongs to J.P.C.D.S., Inc., and may only be used togther
* with linkcollector.php to create link sites as described on ownlinksite.com.
* Any other copying or use of this program is not permitted. 
* 
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
***********************************************************************/

    var $_url_1;  // Url to the image to be downloaded, alterntive 1
                  // This should be the URL to a pick
    var $_url_2;  // Url to the image to be downloaded, alternative 2 (large)
                  // This could be the URL to a large image, if available
                  
    var $_img;    // The downloaded picture
    var $_download_ok = false; // Changes to true fter successful download
    
    // Picture size
    var $_old_w;        // Picture original width, pixels
    var $_old_h;        // Picture original height, pixels
    var $_min_old_w=50; // Reject if original width is smaller
    var $_min_old_h=50; // Reject if original height is smaller
    var $_k_cut = 1.5;  // If 1, the whole picutre used to make pick.
                        // If 2, only half the pictures is used and so on
    var $_k_size;      // Factor: New size/Old size, taking into acount
                        // the re-sized pick must fill both w and h

    var $_new_w = 80;  // Picture width after being re-sized, with default value
    var $_new_h = 100;  // Picture height after being re-sixed, with default value
    
    // Reject criteria for GD download
    var $_min_n_colors=50;  // Reject if fewer colors (or greyscales)
                            // NB: If image is very small, this value is reduced automativally.
    
    // Reject criteria for non-GD download types
    var $_min_bytes = 2048;    // Reject if downloaded pick is smaller
    var $_max_bytes = 7168;    // Reject if downloaded pick is larger
        
    // Paramters determining which methods are available. Innocent until prooven guilty.
    var $_resize = true;    // Functions for re-sizing the pick is available
    var $_count_colors = true; // Functions for counting colors are available
    var $_truecolor_ok = true; // The best function for formating image type is available 
    var $_resampled_ok = true; // The best function for image reduction is available
    var $_url_in_use;      // URL in use (either _url_1 or _ur_2)

    
    // Feedback to user
    var $_info_level = 2; // 0: no feedbac
                        // 1: show only errors
                        // 2: show errors and warnings
                        // 3: show error, warnings and general info.
    var $_message;      // Messages generated during download
                        // $_message[1] = array with errors
                        // $_message[2] = array with warnings
                        // $_message[3] = array with general info

    
function getpick($url_1, $url_2=false)  {
/***********************************************************************
* Constructor.
***********************************************************************/

    // Simple checking of url arguments
    if (strlen($url_1) < 4)  {  // No sensible main URL given, abandon
        $this->_message[1][] = "The URL sent as first <i>$url_1</i> 
                                argument to constructor was rejected,
                                getpick object is not created"; 
        print $this->messages_to_html();
        return 0;
    } elseif ($url_2 && strlen($url_2) < 4)  { // url_2 given, but not sensible
        $url_2 = false;  // Reject if invalide
    }
    // Make sure they start with http:// if not from harddisk (ex. c: ...)
    if(          !eregi('^http://',$url_1) && $url_1[1]!=':')  $url_1 = 'http://'.$url_1;
    if($url_2 && !eregi('^http://',$url_2) && $url_2[1]!=':')  $url_2 = 'http://'.$url_2;
    $this->_url_1 = $url_1;
    $this->_url_2 = $url_2;
    $this->_url_in_use = $this->_url_1; // Dafault, start by using pick url
    
    // Select methods according to this server's setup
    $this ->selections();
}

function selections()  {
/***********************************************************************
* Determine which methods and which url to use for downloading
***********************************************************************/

    // Determine if GD-lib functions used for image resizing is available
    $resize_functions = array('imagecreatefromjpeg','imagecreate','imagejpeg');
    foreach($resize_functions as $resize_function)  {
        $this->_resize *= function_exists($resize_function); // False if any is missing
    }
    
    // If no re-sizing, use the pick url 
    if(!$this->_resize)  {
        $this->_message[2][] = 'Necessary GD-lib funtions for re-sizing the pick
                                to preferred size is not available, so the result
                                may not fit requested size'; 
    }
        
    // Make a separate message regarding how the downloader works
    if(!function_exists('imagecreatetruecolor'))  {
        $this->_truecolor_ok  = false;
        $this->_message[2][] = 'The GD-function <i>imagecreatetruecolor</i>
                                used to create new image when reducing image
                                size does not exist, so the
                                less good <i>imagecreate</i> is being used.
                                Depending on how other parameters are set up,
                                that may lead to blank pictures on some servers.
                                Solution: Install latest GD-library php - go to 
                                php.net and search for GD-library for more info.,
                                or rent another server with more updated php.';
    }
                                
    // Which function to use for the actual image resize
    if(!function_exists('imagecopyresampled'))  {
        $this->_resampled_ok  = false;
        $this->_message[2][] = 'The GD-function <i>imagecopyresampled</i>
                                used to reduce image size does not exist, so the.
                                less good <i>imagecopyresized</i> needs to be used.
                                Expect sligthly reduced quality.';
    }

    // Check if necessary functions for counting colors in result are available
    if(!function_exists('imagecolorat') || !function_exists('imagecreatetruecolor'))  {
        $this->_count_colors = false;
        $this->_message[2][] = 'The GD-functions <i>imagecolorat</i> and/or 
                                <i>imagecreatetruecolor</i>, used to check
                                image quality, is not available in your verion
                                of the GD-library. That increases chances of
                                erronous images being accepted in the results';
    }
}

function messages_to_html()  {
/***********************************************************************
* Re-format all messages into a html string
***********************************************************************/

    // Just return if there are no messages
    if(!is_array($this->_message) || !$this->_info_level)  return 0;
    
    $types = array(1=>'<b><font color="#FF0000">Error: </b></font>',
                  2=>'<b>Warning </b>',
                  3=>'<b>Info: </b>');
                  
    if($this->_info_level == 3)  { // Add info. about all variables
        $vars=array('_url_1','_url_2','_old_w','_old_h',
                    '_new_w','_new_h','_min_bytes','_max_bytes',
                    '_resize','_count_colors','_url_in_use',
                    '_info_level','_k_size','_resampled_ok','_truecolor_ok');
        foreach($vars as $var)  {
            $this->_message[3][] = "$var: ".$this->$var;
        }
    }
    
    $text = '';
    foreach($this->_message as $type_code=>$value)  {
        foreach($value as $no => $msg)  {
            if($type_code <= $this->_info_level)  {  // Should be displayed
                $text .= $types[$type_code].$msg.'<br>';
            }
        }    
    }
    return $text;
}

function gdlib_colors_ok()  {
/***********************************************************************
* This function is used to check the number of colors in the
* resized pick, and used to determine if the final result is OK
***********************************************************************/

    $colors = array();
    // Determine smalles dimention (width or hight, remove the px-text)
    $min_dim = min(str_replace('px','',$this->_new_w),
                  str_replace('px','',$this->_new_h));
                                        
    for($pix_coord=0; $pix_coord<$min_dim; $pix_coord++)  {
        // Define the cell if it does not exist, and count colors
        $colors[imagecolorat($this->_img,$pix_coord,$pix_coord)] = 1;
    }
        
    // Modify required number of colors if the pick is very small
    $this->_min_n_colors = min($this->_min_n_colors, $min_dim*.6);
        
    if(count($colors) >= $this->_min_n_colors)  { // Success!
        $this->_download_ok = true;
        return true;
    } else {
        $this->_message[3][] = "The downloaded pick contained $n_colors colors";
        return false;
    }
}

function gdlib_download()  {
/***********************************************************************
* Download the image using gd-lib
***********************************************************************/

    if(!($this->_img = @imagecreatefromjpeg($this->_url_in_use)))  {
        $this->_message[2][] = "Unable to download pick from ".
                                $this->_url_in_use;
        return false;
    }
    
    $this->_old_w = imagesx($this->_img);
    $this->_old_h = imagesy($this->_img);
        
    // Expect final quality to be too poor if source image too small
    if($this->_old_w < $this->_min_old_w || $this->_old_h < $this->_min_old_h)  {
        $this->_message[2][] = "The pick turned out to be too small 
                                and was rejeted.";
        return 0;
    }
        
    // Chck if the dowloaded image's size is as smaller than the pick to be created
    if($this->_old_w < $this->_new_w || $this->_old_h < $this->_new_h)  {
    
        // If url for a larger version of the image is available, use it
        if($this->_url_2 && $this->_url_in_use != $this->_url_2)  {
            $this->_url_in_use = $this->_url_2;
            return $this->gdlib_download();
        } else {  // Have to accept increasing pick page, make warning and go on with it
            $this->_message[2][] = "One of the downloaded picks is smaller than the 
                                    pick to be created. Increasing pick size
                                    generally leads to quality reduction. If this warning 
                                    is generated few times compared to the number of picks generated, it
                                    may not be anything to worry about.";
        }
    }
        
    // Find out how much the picture should be reduced
    $k_w = $this->_new_w/max(1,$this->_old_w); // Preferred width scaling factor
    $k_h = $this->_new_h/max(1,$this->_old_h); // Preferred height scaling factor
    // Only cut away part of image if it does not mean having to incres the size of the rest
    $this->_k_size = max(max($k_w, $k_h),min(1,$this->_k_cut*max($k_w, $k_h)));
            
    if ($this->_truecolor_ok)  {  // Only on newest php. Best result.
        $new_pick = imagecreatetruecolor($this->_new_w, $this->_new_h);
    } else { // Accept the less good imagecreate if imagecreatetruecolor unavailable
        $new_pick = imagecreate($this->_new_w, $this->_new_h);
    }
        
    $x0 = .5*($this->_old_w-$this->_new_w/$this->_k_size); // Use top center part of pick is 
    if ($this->_resampled_ok)  {  // Best result, use if available.
        imagecopyresampled ($new_pick, $this->_img, 0, 0, $x0, 0, 
                            $this->_new_w,$this->_new_h,
                            $this->_new_w/$this->_k_size,$this->_new_h/$this->_k_size);
    } else {
        imagecopyresized ($new_pick, $this->_img, 0, 0, $x0, 0, 
                          $this->_new_w,$this->_new_h,
                          $this->_new_w/$this->_k_size,$this->_new_h/$this->_k_size);    
    }
    $this->_img = $new_pick;
        
    if($this->_count_colors)  {  // Count colors to estimate image quality if possible
        return $this->gdlib_colors_ok();
    } else {// Have no way to check number of colors, accept by default
            $n_colors_ok = true;
            $this->_message[3][] = "Unable to count colors in pick, had to accept by default";
    }
        
        // Accept if enough colors
        if($n_colors_ok)  {  // Probably OK image
            return ($this->_download_ok = true);
        } else {
            $this->_message[2][] = "The downloaded pick contained only $n_colors colors,
                                    which is too few, so it was rejected";
            return false;
        }
}


function direct_download()  {
/***********************************************************************
* Use this function to read the image if the GD-library
* is not available.
*
* Note that thios is only going to work for picks
* (size limits used to accept/reject, and the fat that it cannot be 
* shrunk later)
***********************************************************************/

    if(!$fp = @fopen($this->_url_in_use,"rb"))  {
        $this->_message[2][] = "Unable to read image at URL $this->_url_in_use";
        return 0;
    }
    $this->_img = fread($fp,$this->_max_bytes);
    if(strlen($this->_img) == $this->_max_bytes)  {
        $this->_message[2][] = "The image appeared to be larger than the 
                                upper limit, which is curently set to ".
                                $this->_max_bytes." bytes. The image 
                                was rejected.";
        return ($this->_img = false);
    } elseif(strlen($this->_img) < $this->_min_bytes) {
        $this->_message[2][] = "The image appeared to be small for lower limit 
                                upper limit, which is curently set to ".
                                $this->_min_bytes." bytes. The image 
                                was rejected.";
        return ($this->_img = false);
    } else {
        return ($this->_download_ok = true);
    }
}

function show_pick_gd()  {
/***********************************************************************
* Shows the pick $this->_img, if there is one.
* Note that no other pick must have been sent to screen for
* this to work.
***********************************************************************/

    if(!@imagejpeg($this->_img,'',100))  {
        print 'Unable to show the image';
        return false;
    } else {
        return true;
    }
}

function show_pick_direct($file='temp_pick.jpg')  {
/***********************************************************************
* Show an image downloaded with the direct-function. Used for testing.
* It does so by writing it to a temporary file called temp_pick.jpg
* and ordering the browser to read from there.
***********************************************************************/

    if(strlen($this->_img) >= $this->_min_bytes)  {
        if($fp = fopen($file, 'w'))  {
            fwrite($fp, $this->_img);
            fclose($fp);
            print "<img src=\"$file\">";
            
            return true;
        } else {
            $this->_message[2][] = "Could not open file $file - please check access
                                    permissions.";
            return false;
        }
    } else {
        $this->_message[2][] = "Found no image to print - has it been downloaded?";
        return false;
    }
}

function save_pick_gd($file)  {
/***********************************************************************
* Save the imge using GD-function
***********************************************************************/

    if(!imagejpeg($this->_img, $file))  {
        $this->_message[2][] = "Could not open file $file to save the image
                                - please check access permissions for directory " .
                                eregi_replace("/[^/]*$",'',$file);
        return false;
    }
}

function save_pick_direct($file)  {
/***********************************************************************
* Saves the image to file $file
***********************************************************************/
    if($fp = fopen($file, 'w'))  {
        fwrite($fp, $this->_img);
        fclose($fp);
        return 1;
    } else {
        $this->_message[2][] = "Could not open file $file to save the image
                                - please check access permissions for directory " .
                                eregi_replace("/[^/]*$",'',$file);
        return false;
    }
}

function download()  {
/***********************************************************************
* Use appropriate method to download
***********************************************************************/

    if($this->_resize) return $this->gdlib_download();
    else              return $this->direct_download();
}
function show_pick()  {
/***********************************************************************
* Use appropriate method to show the pick
***********************************************************************/

    if($this->_resize) return $this->show_pick_gd();
    else              return $this->show_pick_direct();
}
function save_pick($file)  {
/***********************************************************************
* Use appropriate method to save the pick
***********************************************************************/

    if($this->_resize) return $this->save_pick_gd($file);
    else              return $this->save_pick_direct($file);
}
}  // END CLASS getpicks



/*BLOCKER*/
    // Uncomment the if-line below to protect linkcollector.php from un-authorized use
    // After un-commenting, the program must be called with the blocker-parameter
    // (in addition to any other arguments to be passed) like so:
    // http://your-site.com/ownlinksite/linkcollector.php?blocker=fb6wbee
//    if($blocker != 'fb6wbee') exit();



// Do the links and picks download using the lincollector class

    print '<div align="center"><h2>Now getting links and picks.</h2>
          <b>It may take a up to a few minutes, depending on your Internet connection - 
              please be patient</b><br></div>'; flush();
    $c_linkcollector = new linkcollector();
    $c_linkcollector->save_everything();

    print $c_linkcollector->_result_arr['message'];        // Messages from OwnLinksSite server
    print '<br>'.$c_linkcollector->messages_presentable(); // Messages from linkcollector

?>





<?php
/***********************************************************************
*
*    ***          links.php PROGRAM LISTING          ***
*    ***  How to use is outlined at ownlinksite.com ***
*
* 07.01.2002 V 1.0 Beta
* 22.04.2003 V 1.1 Stable
* 26.07.2003 V 2.0 Major update
* 30.09.2003 V 2.1 Some small bug fixes
*
* Place the code in a sub-directory called ownlinksite and name it
* links.php.
* Also, put pagetransform.php and linkcollector.php in the same directory.
*
* This program transfers a template link page into an actual, working
* php-based link page, as described in the tutorial how_to.php
*
* All rights reserverd J.P.C.D.S., Inc.
* 
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
* 
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
***********************************************************************/

class links  {

    var $_n_days_links;                // Number of days with links (from today and older)
    var $_n_days_picks;                // Number of days with picks
    var $_categories_links;            // Array with all textlink categories
    var $_categories_picks;            // Array with all pick categories

    var $_ok_files = array();  // Paths to already downloaded, OK link and pick files


function links($n_days_links=0,$n_days_picks=0,$categories_links=0,$categories_picks=0)  {
/***********************************************************************
* Constructor
***********************************************************************/

    // The parameters not passed as arguments should be read from file
    if(!$n_days_links)  {
        $this->_n_days_links    = $this->binary_read('ownlinksite/pagedata/n_days_links.txt');
    } else {
        $this->_n_days_links    = $n_days_links;
    }
    if(!$n_days_picks)  {
        $this->_n_days_picks    = $this->binary_read('ownlinksite/pagedata/n_days_picks.txt');
    } else {
        $this->_n_days_picks    = $n_days_picks;
    }
    if(!is_array($categories_links))  {
        $this->_categories_links = array_keys(unserialize($this->binary_read('ownlinksite/pagedata/links_each_cat.txt')));
    } else {
        $this->_categories_links = $categories_links;
    }
    if(!is_array($categories_picks))  {
        $this->_categories_picks = array_keys(unserialize($this->binary_read('ownlinksite/pagedata/picks_each_cat.txt')));
    } else {
        $this->_categories_picks = $categories_picks;
    }

    // Check for available links and picks (those downloaded before)
    $this->downloaded_files();
}

function check_downloaded_files($timestamp_start,$links_or_picks='links')  {
/***********************************************************************
* Fills in _ok_files for links or picks
***********************************************************************/

    if($links_or_picks=='links')  {
        $n_days = $this->_n_days_links;
        $prefix  = 'x';
        $categories_links = '_categories_links';
    } else { // Asume picks
        $n_days = $this->_n_days_picks;
        $prefix  = 'y';
        $categories_links = '_categories_picks';
    }
    
    // Check for available files, and fill in if missing
    if(is_array($this->$categories_links)) {
    foreach($this->$categories_links as $id_category)  {
        if(isset(  $link_files)) unset($link_files);    // Empty
        if(isset($no_link_files)) unset($no_link_files); // Empty

        for($day_of_interest=0; $day_of_interest<$n_days; $day_of_interest++)  {
            $day_index = $this->day_index($timestamp_start,$n_days,$day_of_interest);

            $file = "ownlinksite/links/$prefix"."_$id_category"."_$day_index.txt";
            
            // Use if it exists. For picks, the picks themselves must also exist.
            if(file_exists($file) && 
            ($links_or_picks=='links' || $this->all_picks_ok($file,$id_category,$day_index)))  {
                $link_files["$prefix$day_of_interest"]      = $file; // OK file
            } else { 
                $no_link_files  ["$prefix$day_of_interest"] = '';  // Cannot use this one
            }
        }

        // If any day of interest for this category does not have a file: Use another
        if(isset($link_files))  {
        if(isset($no_link_files) && is_array($link_files))  {
            $link_copy = $link_files;
            foreach($no_link_files as $filename=>$file)  {
                $value = array_shift($link_copy);
                $no_link_files[$filename] = $value;
                $link_copy[] = $value; // Make sure it does not run dry
            }
            $this->_ok_files[$links_or_picks][$id_category] = array_merge($link_fi

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Jim

Comment:



Comment:

(Maximum characters: 1200). You have characters left.