Page 3 of 3 FirstFirst 123
Results 21 to 24 of 24
  1. #21
    Join Date
    Sep 2012
    Location
    West Jefferson, NC
    Posts
    383
    Plugin Contributions
    0

    Default Re: When To Use A Custom Function When Developing Admin App?

    I didn't see anywhere to attach a file...so, sorry for the whole script.

    I'll just show you my download.php file and ask what would you make functions, classes, or procedural php coding...the more I read, the more confused I get.

    What I'm leaning towards making a function is obtaining the chosen link from the database and all the mess associated with adding or deleting the link from the link list...as marked in the script. I could do the same thing by forking to another php file...

    However, I don't see the point in moving any of this out of the download.php file since it is not used anywhere else in my programming and because moving it out would take away from the readability of my download process...and the script is not so big that it warrants breaking it down.

    The only duplication between my files is the fopen, data manipulation, and fclose process. But the processes are not identical...since the data manipulation changes according to the purpose of the script. I.E. download.php simply grabs the datafeed and puts it into a text file, clean.php gets rid of all the trash records and lets the users see the data before committing it to the database, update.php does some comparisons against the active products and prepares the incoming data to be inserted or updated in the live shop.

    So, yes, I'm confused and thick headed.

    Thanks.

    It's Friday night, let's go have some fun!

    PHP Code:
    <?php
    /**
     * @package EZ-Feeds
     * @copyright Copyright 2003-2016 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @copyright Copyright 2017 Jest Country Enterprises
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: Author: mikeel100 Wed Sep 13 12:29:00 2017 +0100 Modified in v1.5.5e $
     */

    //+++++++++++++++++++START FUNCTION+++++++++++++++++++++++++

    //MAKE SURE LINK IS SELECTED    
        
    if(empty(EZ_FEEDS_DEFAULT_FEED) and empty 
            
    EZ_FEEDS_ADD_REMOVE_DATAFEED_LINK)) {
            
    $messageStack->add_session(ERROR_FEED_LINK_EMPTYTEXT_ERROR);
            
    $stopUpdate true;
        }
    //SET FEED LINK TO DEFAULT LINK    
        
    if(!empty(EZ_FEEDS_DEFAULT_FEED)) {
            
    $feed_link strstr(EZ_FEEDS_DEFAULT_FEEDTEXT_HTTPS);
        }
        
    //$feed_link = ezfeeds_clean_string(EZ_FEEDS_DEFAULT_FEED, TEXT_HTTPS);
    //SEE IF NEW LINK EXISTS IN LIST
        
    if(!empty(EZ_FEEDS_ADD_REMOVE_DATAFEED_LINK)) {    
            
    $find_me $db->execute("select `set_function` from " TABLE_CONFIGURATION 
                    where `configuration_key` = 'EZ_FEEDS_DEFAULT_FEED' "
    );
            
    $current_feed_list_no_slashes $find_me->fields['set_function'];
            if(
    $pos strpos($current_feed_list_no_slashes
                    
    EZ_FEEDS_ADD_REMOVE_DATAFEED_LINK) !== false
            
    and EZ_FEEDS_DEFAULT_FEED !== EZ_FEEDS_ADD_REMOVE_DATAFEED_LINK) {
                
    $stopUpdate true;
                
    $messageStack->add_session(ERROR_FEED_LINK_EXISTS 
                            
    EZ_FEEDS_ADD_REMOVE_DATAFEED_LINKTEXT_ERROR);
            }
    //ADD NEW LINK IF ALL IS GOOD
            
    if(EZ_FEEDS_DEFAULT_FEED !== EZ_FEEDS_ADD_REMOVE_DATAFEED_LINK and 
                    
    $stopUpdate !== true) {
                if(
    $pos strpos(EZ_FEEDS_ADD_REMOVE_DATAFEED_LINKTEXT_HTTPS) !== 
                            
    false) {
                    
    $feed_link strstr(EZ_FEEDS_ADD_REMOVE_DATAFEED_LINK
                                    
    TEXT_HTTPS);
                    
    //$feed_link = ezfeeds_clean_string
                                   // (EZ_FEEDS_ADD_REMOVE_DATAFEED_LINK, TEXT_HTTPS);
                    
    $current_feed_list addslashes($current_feed_list_no_slashes);
                    if (
    strpos($current_feed_list'(),') !== false) {
                        
    $new_link substr_replace($current_feed_list'\\\'' 
                                            
    EZ_FEEDS_ADD_REMOVE_DATAFEED_LINK '\\\'', -30);
                    } else {
                        
    $new_link substr_replace($current_feed_list',\\\'' 
                                            
    EZ_FEEDS_ADD_REMOVE_DATAFEED_LINK '\\\'', -30);
                    }
                    
    $db->execute("update " TABLE_CONFIGURATION " set `set_function` 
                                    = '
    $new_link', `configuration_value` = '" 
                                    
    EZ_FEEDS_ADD_REMOVE_DATAFEED_LINK "'
                    where `configuration_key` = 'EZ_FEEDS_DEFAULT_FEED' "
    );
                    
    $db->execute("update " TABLE_CONFIGURATION " set 
                                    `configuration_value` = ''
                    where `configuration_key` = 'EZ_FEEDS_ADD_REMOVE_DATAFEED_LINK' "
    );
                    
    $messageStack->add_session(TEXT_FEED_ADDED 
                                    
    EZ_FEEDS_ADD_REMOVE_DATAFEED_LINKTEXT_SUCCESS);
                } else {
                    
    $stopUpdate true;
                    
    $messageStack->add_session(ERROR_NEW_LINK 
                                    
    EZ_FEEDS_ADD_REMOVE_DATAFEED_LINKTEXT_ERROR);
                }
            }
    //REMOVE LINK

            
    if(EZ_FEEDS_DEFAULT_FEED == EZ_FEEDS_ADD_REMOVE_DATAFEED_LINK) {
                
    $current_feed_list_trashed str_ireplace(EZ_FEEDS_DEFAULT_FEED''
                            
    $current_feed_list_no_slashes);
                
    $current_feed_list_trashed str_replace("(''),""(),"$current_feed_list_trashed);
                
    $current_feed_list_trashed str_replace("('',""("$current_feed_list_trashed);
                
    $current_feed_list_trashed str_replace(",''),""),"$current_feed_list_trashed);
                
    $current_feed_list_trashed str_replace(",'',"","$current_feed_list_trashed);
                
    $current_feed_list addslashes($current_feed_list_trashed);            
                
    $db->execute("update " TABLE_CONFIGURATION " set `set_function` 
                            = '
    $current_feed_list', `configuration_value` = '' where `configuration_key` 
                            = 'EZ_FEEDS_DEFAULT_FEED' "
    );
                
    $stopUpdate true;
                
    $messageStack->add_session(TEXT_FEED_REMOVED 
                            
    EZ_FEEDS_ADD_REMOVE_DATAFEED_LINKTEXT_SUCCESS);        
            }    
        }
    //SEE IF LINK WORKS
        
    $supplier str_replace(TEXT_HTTPS''$feed_link);
        
    $supplier substr($supplier0strpos$supplierTEXT_DOT_COM)) . TEXT_DOT_COM;    
        if(
    $socket =@ fsockopen($supplier80$errno$errstr30) or $stopUpdate) {
            
    fclose($socket);
        } else {
            
    $stopUpdate true;
            
    $messageStack->add_session(ERROR_SERVER_DOWNTEXT_ERROR);
        }
    //++++++++++++++++++++++++STOP FUNCTION++++++++++++++++++++++++++
    //CHECK NUMBER OF SPLIT RECORDS
        
    if(EZ_FEEDS_SPLIT_DOWNLOAD_RECORDS 20000) {
            
    $messageStack->add_session(ERROR_SPLIT_RECORDS_BADTEXT_ERROR);
            
    $stopUpdate true;
        }
    //STOP IF SOMETHING IS WRONG    
        
    if($stopUpdate) {
            
    $feed_link '';
            
    $db->execute("update " TABLE_CONFIGURATION " set `configuration_value` = ''
            where `configuration_key` = 'EZ_FEEDS_ADD_REMOVE_DATAFEED_LINK' "
    );
        } else {
    //DELETE OLD FILES        
            
    foreach (glob(DIR_EZ_FEEDS_TEMP TEXT_GLOBAL_TEXT) as $filename) {
                if (
    is_file($filename)) {
                    
    unlink($filename);
                }
            }
            if(
    EZ_FEEDS_SPLIT_DOWNLOAD_FILES <> 1) {
                
    $db->execute("update " TABLE_CONFIGURATION ." set configuration_value = 1
                         where configuration_key = '" 
    TEXT_CONFIG_SPLIT_FILES "' ");
            }
    //DOWNLOAD IF ALL IS GOOD        
            
    if (($dirty_file fopen($feed_linkTEXT_FOPEN_READ_BINARY)) !== FALSE) {
                
    $datafeedCounter 1;
                
    $limitCounter 1;
                
    $f 1;
                
    $limit EZ_FEEDS_SPLIT_DOWNLOAD_RECORDS;
                while ((
    $row fgets($dirty_file)) !== false) {    
                    if(
    $datafeedCounter == 1) {
    //TO DO: DETERMINE FIELD DELIMITER AND SET TO VARIABLE
    //DELIMITERS - |  <XML> \t ^ OR A CUSTOMIZABLE USER DEFINED DELIMITER
    //TO DO: REPLACE FIELD DELIMITERS WITH COMMA
                        
    $headers $row;
                    }        
                    if (
    $limitCounter == 1) {
                        
    $raw_feed FILENAME_EZFEEDS_RAW_FEED $f TEXT_EXTENSION;
                        
    $split_data fopen($raw_feedTEXT_FOPEN_APPEND_BINARY);
                        
    fwrite($split_data$headers);
                    }
                    if(
    $datafeedCounter !== 1) {
    //TO DO: REPLACE FIELD DELIMITERS WITH COMMA
                        
    fwrite($split_data$row);
                    }
                    if(
    $limitCounter == $limit) {    
                        
    fclose($split_data);
                        
    $limitCounter 0;
                        
    $f++;
                    }
                    
    $limitCounter++;
                    
    $datafeedCounter++;    
                } 
    //end while
                
    fclose($split_data);
    //UPDATE NUMBER OF SPLIT FILES            
                
    $db->execute("update " TABLE_CONFIGURATION ." set configuration_value 
                            = '
    $f' where configuration_key = '" TEXT_CONFIG_SPLIT_FILES "' ");
    //SET UPDATE DATE
                
    $db->execute("update " TABLE_CONFIGURATION ." set configuration_value 
                            = '" 
    TEXT_TODAY "' where configuration_key = '" 
                            
    TEXT_CONFIG_LAST_UPDATE "' ");
                if(
    $f 1) {
                    
    $messageStack->add_session(CAUTION_SPLIT_FILES $fTEXT_CAUTION);
                }
                if (!
    feof($dirty_file)) {
                    
    $messageStack->add_session(ERROR_FEOF_FAILURE $datafeedCounter
                                    
    TEXT_ERROR);
                    
    $stopUpdate true;
                }
                
    fclose($dirty_file);
                
    $datafeedCounter $datafeedCounter 2;
            }
        }    
        unset(
    $socket$feed_link$filename$dirty_file$supplier$errno$errstr$limitCounter$f$limit$split_data$raw_feed$headers$row);
    ?>

  2. #22
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,691
    Plugin Contributions
    9

    Default Re: When To Use A Custom Function When Developing Admin App?

    Quote Originally Posted by mikeel100 View Post
    I think I'll just avoid using catalog side functions in admin until the powers that be decide how and when to have only one naming system for all functions.

    Wouldn't classes solve that problem?

    That is my conclusion after reading for hours last night on when to use a class versus a function...but I may have misunderstood.

    Thanks.
    classes would not solve that problem. for example, see:

    includes/classes/order.php
    admin/includes/classes/order.php

    you still need to load from the catalog side. again, one of my biggest issues. have the admin extend the existing order class if need be, but redefining a lot of the same things is not good design. and i know the ZC team is aware and incorporating as we move forward.

    best.
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  3. #23
    Join Date
    Sep 2012
    Location
    West Jefferson, NC
    Posts
    383
    Plugin Contributions
    0

    Default Re: When To Use A Custom Function When Developing Admin App?

    Quote Originally Posted by carlwhat View Post
    classes would not solve that problem. for example, see:

    includes/classes/order.php
    admin/includes/classes/order.php

    you still need to load from the catalog side. again, one of my biggest issues. have the admin extend the existing order class if need be, but redefining a lot of the same things is not good design. and i know the ZC team is aware and incorporating as we move forward.

    best.
    Point taken...be careful when naming functions and files.

  4. #24
    Join Date
    Sep 2012
    Location
    West Jefferson, NC
    Posts
    383
    Plugin Contributions
    0

    Default Re: When To Use A Custom Function When Developing Admin App?

    I think I have a handle on it now...may be wrong. LOL

    At least it is a starting point.

    These functions (and probably a few more) are repeated throughout my files.

    PHP Code:
    //used in 1 file multiple times

     
    function ezfeeds_clean_string($dirty_string$needle) {
         
    $cleaned_string strstr($dirty_string$needle);
         return 
    $cleaned_string;
     }

    //used in 5 different files multiple times
     
     
    function ezfeeds_unlink($file_name) {
        if (
    file_exists($file_name) or is_file($file_name)) {
            
    unlink($file_name);
        }      
     }

    //used in 3 different files multiple times

     
    function ezfeeds_unlink_files($file) {
        global 
    $file_counter;    
        foreach (
    glob($file) as $filename) {        
            if (
    is_file($filename)) {
                
    $file_counter++;
                if (
    $file_counter == EZ_FEEDS_SPLIT_DOWNLOAD_FILES) {
                    foreach (
    glob($file) as $filename) {        
                        
    unlink($filename);
                    }
                    
    $file_counter 0;
                    return 
    $file_counter;
                }
            }
        }     
     }

    //5 different places in my image management script and 2 in backup script

     
    function ezfeeds_mkdir($path) {
        if (!
    is_dir($path) or !file_exists($path)) {
            
    mkdir($path0777true);
        } 
     } 
    There's one doozy that will take days to figure out.

    Thanks again for your insight.

    Mike

 

 
Page 3 of 3 FirstFirst 123

Similar Threads

  1. Replies: 8
    Last Post: 11 Oct 2012, 12:21 AM
  2. Replies: 3
    Last Post: 11 Apr 2011, 02:08 PM
  3. custom 404 error when changing the admin name
    By ray-the-otter in forum General Questions
    Replies: 6
    Last Post: 26 Oct 2010, 12:14 PM
  4. Replies: 2
    Last Post: 31 Jul 2007, 02:40 AM
  5. Added SSL, Now have Parse Error when trying to use ADMIN
    By minson in forum General Questions
    Replies: 2
    Last Post: 22 Mar 2007, 02:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR