Changeset 10


Ignore:
Timestamp:
Sep 12, 2005 1:02:01 AM (19 years ago)
Author:
scdev
Message:

update module_maker to print module variables instead of writing files

Files:
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/1.1dev/lib/Utilities.inc.php

    r3 r10  
    206206
    207207/**
     208 * Encodes an email into a user (at) domain (dot) com format.
     209 *
     210 * @access  public
     211 * @param   string   $email   An email to encode.
     212 * @param   string   $at      Replaces the @.
     213 * @param   string   $dot     Replaces the ..
     214 * @return  string   Encoded email.
     215 */
     216function encodeEmail($email, $at='-at-', $dot='-dot-')
     217{
     218    $search = array('/@/', '/\./');
     219    $replace = array($at, $dot);
     220    return preg_replace($search, $replace, $email);
     221}
     222
     223/**
    208224 * Return a human readable filesize.
    209225 *
  • trunk/bin/module_maker/_config.inc.php

    r9 r10  
    44
    55// Determine common site directory.
    6 if (false !== ($common_base = realpath($_SERVER['argv'][1]))) {
     6$common_base = realpath($_SERVER['argv'][1]);
     7
     8if ('' != $common_base && is_dir($common_base)) {
    79    // First arg is path to current site. Realpath removes trailing /s
    810    define('COMMON_BASE', $common_base);
    911} else {
    10     die(sprintf("Error: First argument must be the directory path to the site (e.g.: /home/sc/www.strangecode.com/).\n", basename($_SERVER['argv'][0])));
     12    die("Error: First argument must be the directory path to an existing site (ex: /home/sc/www.strangecode.com).\n");
    1113}
    1214
     
    2527$app->setParam(array(
    2628    'site_name' => 'Module Maker',
    27     'site_email' => 'quinn@strangecode.com',
     29    'site_email' => 'codebase@strangecode.com',
    2830    'enable_session' => false,
    2931    'enable_db' => true,
  • trunk/bin/module_maker/module.cli.php

    r9 r10  
    99
    1010$op = null;
    11 $valid_ops = array('clean');
     11$valid_ops = array('clean', 'var');
    1212
    1313// Test for a single argument.
     
    176176// -------------FILES-------------
    177177
    178 $skel_files['admin_script'] = file_get_contents($skel_dir . '/admin.php');
    179 $skel_files['admin_list_template'] = file_get_contents($skel_dir . '/adm_list.ihtml');
    180 $skel_files['admin_form_template'] = file_get_contents($skel_dir . '/adm_form.ihtml');
    181 $skel_files['public_script'] = file_get_contents($skel_dir . '/public.php');
    182 $skel_files['public_list_template'] = file_get_contents($skel_dir . '/public_list.ihtml');
    183 $skel_files['public_detail_template'] = file_get_contents($skel_dir . '/public.ihtml');
     178$skel_files['skel_admin_script'] = file_get_contents($skel_dir . '/admin.php');
     179$skel_files['skel_admin_list_template'] = file_get_contents($skel_dir . '/adm_list.ihtml');
     180$skel_files['skel_admin_form_template'] = file_get_contents($skel_dir . '/adm_form.ihtml');
     181$skel_files['skel_public_script'] = file_get_contents($skel_dir . '/public.php');
     182$skel_files['skel_public_list_template'] = file_get_contents($skel_dir . '/public_list.ihtml');
     183$skel_files['skel_public_detail_template'] = file_get_contents($skel_dir . '/public.ihtml');
    184184
    185185
     
    333333
    334334/******************************************************************************
     335 * PRINT VAR INSTEAD.
     336 *****************************************************************************/
     337
     338if ('var' == $op) {
     339    if (isset($replace[$_SERVER['argv'][5]])) {
     340        echo "\n\n" . $replace[$_SERVER['argv'][5]] . "\n\n";
     341    } else if (isset($skel_files[$_SERVER['argv'][5]])) {
     342        echo "\n\n" . preg_replace($search, $replace, $skel_files[$_SERVER['argv'][5]]) . "\n\n";
     343    } else {
     344        die(basename($_SERVER['argv'][0]) . " Error: variable " . $_SERVER['argv'][5] . " not defined. Please choose one of:\n" . join(', ', array_keys(array_merge($replace, $skel_files))) . "\n");
     345    }
     346    die;
     347}
     348
     349
     350/******************************************************************************
    335351 * WRITE FILES
    336352 *****************************************************************************/
     
    342358    echo "Writing admin script: $admin_dir/$admin_script\n";
    343359    $fp = fopen("$admin_dir/$admin_script", "w");
    344     fwrite($fp, preg_replace($search, $replace, $skel_files['admin_script']));
     360    fwrite($fp, preg_replace($search, $replace, $skel_files['skel_admin_script']));
    345361    fclose($fp);
    346362}
     
    352368    echo "Writing admin list template: $admin_tpl_dir/$admin_list_template\n";
    353369    $fp = fopen("$admin_tpl_dir/$admin_list_template", "w");
    354     fwrite($fp, preg_replace($search, $replace, $skel_files['admin_list_template']));
     370    fwrite($fp, preg_replace($search, $replace, $skel_files['skel_admin_list_template']));
    355371    fclose($fp);
    356372}
     
    362378    echo "Writing admin form template: $admin_tpl_dir/$admin_form_template\n";
    363379    $fp = fopen("$admin_tpl_dir/$admin_form_template", "w");
    364     fwrite($fp, preg_replace($search, $replace, $skel_files['admin_form_template']));
     380    fwrite($fp, preg_replace($search, $replace, $skel_files['skel_admin_form_template']));
    365381    fclose($fp);
    366382}
     
    372388    echo "Writing public script: $public_dir/$public_script\n";
    373389    $fp = fopen("$public_dir/$public_script", "w");
    374     fwrite($fp, preg_replace($search, $replace, $skel_files['public_script']));
     390    fwrite($fp, preg_replace($search, $replace, $skel_files['skel_public_script']));
    375391    fclose($fp);
    376392}
     
    382398    echo "Writing public list template: $public_tpl_dir/$public_list_template\n";
    383399    $fp = fopen("$public_tpl_dir/$public_list_template", "w");
    384     fwrite($fp, preg_replace($search, $replace, $skel_files['public_list_template']));
     400    fwrite($fp, preg_replace($search, $replace, $skel_files['skel_public_list_template']));
    385401    fclose($fp);
    386402}
     
    392408    echo "Writing public detail template: $public_tpl_dir/$public_detail_template\n";
    393409    $fp = fopen("$public_tpl_dir/$public_detail_template", "w");
    394     fwrite($fp, preg_replace($search, $replace, $skel_files['public_detail_template']));
     410    fwrite($fp, preg_replace($search, $replace, $skel_files['skel_public_detail_template']));
    395411    fclose($fp);
    396412}
  • trunk/bin/module_maker/skel/admin.php

    r9 r10  
    186186        %SET_VALUES_DEFAULT%,
    187187        'new_op' => 'insert',
    188         'submit_buttons' = array(
    189             'submit'   => _("Add %ITEM_TITLE%"),
    190             'repeat'   => _("Add & repeat"),
    191             'cancel'   => _("Cancel")
     188        'submit_buttons' => array(
     189            'submit' => _("Add %ITEM_TITLE%"),
     190            'repeat' => _("Add & repeat"),
     191            'cancel' => _("Cancel"),
    192192        ),
    193193    );
     
    202202    if ($lock->isLocked() && !$lock->isMine()) {
    203203        $lock->dieErrorPage();
    204     } else {
    205         // Get the information for the form.
    206         $qid = DB::query("
    207             SELECT *
    208             FROM %DB_TBL%
    209             WHERE %PRIMARY_KEY% = '" . addslashes($id) . "'
    210         ");
    211         if (!$frm = mysql_fetch_assoc($qid)) {
    212             App::logMsg('Could not find record with %PRIMARY_KEY%: ' . $id, LOG_WARNING, __FILE__, __LINE__);
    213             App::raiseMsg(sprintf(_("The requested record %s could not be found"), $id), MSG_ERR, __FILE__, __LINE__);
    214             App::dieBoomerangURL();
    215         }
    216    
    217         // Lock this record.
    218         $lock->set('%DB_TBL%', '%PRIMARY_KEY%', $id, $frm['address']);
    219        
    220         // Set misc values for the form.
    221         $frm['new_op'] = 'update';
    222         $frm['submit_caption'] = _("Save changes");
    223         $frm['repeat_caption'] = _("Save & edit next");
    224         $frm['reset_caption']  = _("Reset");
    225         $frm['cancel_caption'] = _("Cancel");
    226         $frm['%PRIMARY_KEY%'] = $id;
    227    
    228         return $frm;
    229     }
     204    }
     205
     206    // Get the information for the form.
     207    $qid = DB::query("
     208        SELECT *
     209        FROM %DB_TBL%
     210        WHERE %PRIMARY_KEY% = '" . addslashes($id) . "'
     211    ");
     212    if (!$frm = mysql_fetch_assoc($qid)) {
     213        App::logMsg('Could not find record with %PRIMARY_KEY%: ' . $id, LOG_WARNING, __FILE__, __LINE__);
     214        App::raiseMsg(sprintf(_("The requested record %s could not be found"), $id), MSG_ERR, __FILE__, __LINE__);
     215        App::dieBoomerangURL();
     216    }
     217
     218    // Lock this record.
     219    $lock->set('%DB_TBL%', '%PRIMARY_KEY%', $id, $frm['address']);
     220   
     221    // Set misc values for the form.
     222    $frm = array_merge(array(
     223        %SET_VALUES_DEFAULT%,
     224        'new_op' => 'update',
     225        'submit_buttons' => array(
     226            'submit' => _("Save changes"),
     227            'repeat' => _("Save & edit next"),
     228            'reset' => _("Reset"),
     229            'cancel' => _("Cancel"),
     230        ),
     231    ), $frm);
     232
     233    return $frm;
    230234}
    231235
  • trunk/docs/example_config.inc.php

    r9 r10  
    99 */
    1010
    11 if (!preg_match('!^/!', __FILE__)) {
     11// __FILE__ must be an absolute directory path, starting with / on unix and X: on windows.
     12if (!preg_match('!^/|^[A-Z]:!', __FILE__)) {
    1213    trigger_error('_config.inc.php include must be specified with an absolute file path (eg: "require_once dirname(__FILE__) . \'/_config.inc.php\';"', E_USER_ERROR);
    1314}
  • trunk/lib/DB.inc.php

    r9 r10  
    160160        $this->_connected = true;
    161161
    162         // Tell MySQL what character set we're useing.
    163         if (preg_match('/^4\.[1-9].*$|^5.*$/', mysql_get_server_info())) {
    164             $this->query("SET NAMES '" . $this->mysql_character_sets[strtolower(App::getParam('character_set'))] . "'");
    165         }
    166        
     162        // Tell MySQL what character set we're useing. Available only on MySQL verions > 4.01.01.
     163        $this->query("/*!40101 SET NAMES '" . $this->mysql_character_sets[strtolower(App::getParam('character_set'))] . "' */");
     164
    167165        return true;
    168166    }
Note: See TracChangeset for help on using the changeset viewer.