/**
 * Main function for the CRUD builder with propel and smarty
 *
 * @param array $conf
 * @author Basilio Briceno <*****@*****.**>
 */
function crud_propel_smarty_builder_main ( &$reg )
{
  $conf =& $reg->conf;

  $def_path = $conf['path']['app'].$conf['path']['def'];

  // validate directory existance
  if ( !file_exists( $def_path ) ) {
    tlalokes_error_msg("Definition Objects directory ($def_path) not existant");
  }

  require_once 'classes/MVCGenerator.php';
  require_once 'classes/DefObj.php';

  // check definition objects
  foreach ( glob( $def_path . '*Def.php' ) as $defile ) {

    // check if Definition Object is marked for build
    $mvc = new MVCGenerator( $conf, $defile );
    if ( $mvc->build ) {
      $mvc->generate();
      echo "<p>{$mvc->name} CRUD has been generated.</p>\n";
    }
  }
}
Beispiel #2
0
  /**
   * Authentication by array
   *
   * @param TlalokesRegistry $reg
   */
  public static function validate ( TlalokesRegistry &$reg )
  {
    if ( count( $_SESSION['profiles'] ) >= 1 ) {

      if ( !file_exists( $reg->conf['path']['app'].'auth.php' ) ) {
        tlalokes_error_msg( 'Authentication: Source file not available' );
      }

      // include auth array
      require $reg->conf['path']['app'].'auth.php';

      // check if role is enabled
      if ( !$auth['roles'][$_SESSION['role']] ) {
        tlalokes_error_msg( 'Authentication: Your role is not enabled' );
      }

      // check if controller is available in profile
      foreach ( $_SESSION['profiles'] as $profile ) {

        if ( isset( $auth['permissions'][$profile]
                                     [$reg->conf['current']['controller']] ) ) {
          // validate access
          foreach ( $auth['permissions'][$profile]
                            [$reg->conf['current']['controller']] as $action ) {

            if ( $action == $reg->conf['current']['action'] ) {
              tlalokes_error_msg( 'Authentication: Your profile has no '.
                                  'access to this action' );
            }
          }
        }
      }
    }
  }
Beispiel #3
0
  /**
   * Authentication by array
   *
   * @param TlalokesRegistry $reg
   */
  public static function validate ( TlalokesRegistry &$reg )
  {
    if ( count( $_SESSION['profiles'] ) >= 1 ) {

      // check if role is enabled
      $roles = AuthRolesBss::getByPK( $_SESSION['role'] );
      if ( is_string( $roles ) ) {
        tlalokes_error_msg( $roles );
      } else {
        if ( $roles['role_status'] == 0 ) {
          tlalokes_error_msg( 'Authentication: Your role is not enabled' );
        }
      }
      // check if controller is available in profile
      foreach ( $_SESSION['profiles'] as $profile ) {

        // get permission
        $p = AuthAccessPermissionsBss::getByCtl( $reg->conf['current']['controller'], $profile );
        if ( !is_string( $p ) ) {
          // validate method access
          $methods = explode( ',', $p['methods'] );
          foreach ( $methods as $method ) {
            if ( $reg->conf['current']['action'] == $method ) {
              tlalokes_error_msg( 'Authentication: Your profile has no '.
                                  'access to this action' );

            }
          }
        }
        unset( $p );
      }
    }
  }
 private function __construct( &$auth )
 {
   if ( !isset( $auth ) ) {
     tlalokes_error_msg( 'Set authentication method in configuration file' );
   }
   // set authentication method
   $this->auth = $auth;
 }
/**
 * Saves files from the temportal path to the preconfigured path
 *
 * @author Basilio Briceno <*****@*****.**>
 * @param stdObj $files
 */
function tlalokes_uploads_save(&$files)
{
    foreach ($files->raw as $file) {
        if ($file['size']) {
            $from =& $file['tmp_name'];
            $to = $files->path['absolute'] . $file['name'];
            if (!@copy($from, $to)) {
                tlalokes_error_msg('Upload save: Cannot write into ' . $files->path['absolute']);
            }
            unset($from);
            unset($to);
        }
    }
}
/**
 * Main function for the Test builder
 *
 * @param array $conf
 * @author Basilio Briceno <*****@*****.**>
 */
function test_builder_main ( &$conf )
{
  $builder = $conf['path']['builder'].'/';

  $ctllr = $conf['path']['app'].$conf['path']['controllers'];
  $views = $conf['path']['app'].$conf['path']['views'];
  $local = $conf['path']['app'].$conf['path']['locales'];

  // copy controller
  if ( !file_exists( $builder.'templates/controller/TestCtl.php' ) ) {
    if ( !copy( $builder.'templates/controller/TestCtl.php', $ctllr.'TestCtl.php' ) ) {
      tlalokes_error_msg( 'Test builder: Cannot copy TestCtl.php', true );
    }
    echo "<p>Test controller copied</p>";
  }

  // copy templates
  if ( !file_exists( $builder.'templates/view/one.tpl' ) ) {
    if ( !copy( $builder.'templates/view/one.tpl', $views.'one.tpl' ) ) {
      tlalokes_error_msg( 'Test builder: Cannot copy one.tpl', true );
    }
    echo "<p>Test template one copied</p>\n";
  }
  if ( !file_exists( $builder.'templates/view/two.tpl' ) ) {
    if ( !copy( $builder.'templates/view/two.tpl', $views.'two.tpl' ) ) {
      tlalokes_error_msg( 'Test builder: Cannot copy two.tpl', true );
    }
    echo "<p>Test template two copied</p>\n";
  }

  // copy locales
  if ( !file_exists( $builder.'templates/_locale/eng.php' ) ) {
    if ( !copy( $builder.'templates/_locale/eng.php', $local.'eng.php' ) ) {
      tlalokes_error_msg( 'Test builder: Cannot copy eng.php', true );
    }
    echo "<p>Test locale english copied</p>\n";
  }
  if ( !file_exists( $builder.'templates/_locale/spa.php' ) ) {
    if ( !copy( $builder.'templates/_locale/spa.php', $local.'spa.php' ) ) {
      tlalokes_error_msg( 'Test builder: Cannot copy spa.php', true );
    }
    echo "<p>Test locale spanish copied</p>\n";
  }
}
/**
 * Includes files for required classes, don't abuse of this feature
 *
 * @author Basilio Briceno <*****@*****.**>
 * @param string $class
 */
function __autoload($class)
{
    // set the class file name
    $file_name = $class . '.php';
    // try to find the class directly
    if (file_exists($file_name)) {
        $file_required = $file_name;
        // find classes into include_path directories
    } else {
        foreach (preg_split('/[' . PATH_SEPARATOR . ']/', get_include_path()) as $path) {
            if (file_exists($path . $file_name)) {
                $file_required = $path . $file_name;
            }
        }
    }
    // if class exists load it
    if (isset($file_required)) {
        if (!is_readable($file_required)) {
            tlalokes_error_msg('Receiver: Cannot read ' . $file_required, true);
        }
        require_once $file_required;
        //echo "<pre>\nautoload..$file_required\n</pre>\n";
    }
}
/**
 * Main function for the Authentication builder by array
 *
 * @param array $conf
 * @author Basilio Briceno <*****@*****.**>
 * @copyright Copyright &copy; 2009 Basilio Brice&ntilde;o Hern&aacute;ndez
 * @license http://www.gnu.org/licenses/gpl.html GNU GPL
 */
function auth_array_builder_main ( &$reg )
{
  $conf =& $reg->conf;
  $builder = $conf['path']['builder'];

  $bss_path = $conf['path']['app'].$conf['path']['bss'];
  $ctl_path = $conf['path']['app'].$conf['path']['controllers'];
  $viw_path = $conf['path']['app'].$conf['path']['views'];
  $loc_path = $conf['path']['app'].$conf['path']['locales'].'eng.php';

  // coping of authentication controller
  if ( !file_exists( $ctl_path.'AuthCtl.php' ) ) {

    // copy AuthCtl
    if ( !@copy( $builder.'/classes/AuthCtl.php', $ctl_path.'AuthCtl.php' ) ) {
      tlalokes_error_msg( 'Cannot copy AuthCtl.php', true );
    } else {
      echo '<p>AuthCtl.php copied to '.$ctl_path."</p>\n";
    }
  }

  // coping of authentication model
  if ( !file_exists( $bss_path.'AuthBss.php' ) ) {

    // copy AuthBss
    if ( !@copy( $builder.'/classes/AuthBss.php', $bss_path.'AuthBss.php' ) ) {
      tlalokes_error_msg( 'Cannot copy AuthBss.php', true );
    } else {
      echo '<p>AuthBss.php copied to '.$bss_path."</p>\n";
    }
  }

  // coping of authentication view
  if ( !file_exists( $viw_path.'tlalokes_auth.tpl' ) ) {

    // copy auth.tpl
    if ( !@copy( $builder.'/view/tlalokes_auth.tpl',
                $viw_path.'tlalokes_auth.tpl' ) ) {
      tlalokes_error_msg( 'Cannot copy authentication view', true );
    } else {
      echo '<p>tlalokes_auth.tpl view copied to '.$viw_path."</p>\n";
    }
  }

  // configuration file
  if ( !file_exists( $conf['path']['app'].'auth.php' ) ) {

    // copy auth.tpl
    if ( !@copy( $builder.'/conf/auth.php', $conf['path']['app'].'auth.php' ) ) {
      tlalokes_error_msg( 'Cannot copy authentication configuration', true );
    } else {
      echo '<p>Authentication configuration file copied to '.$viw_path."</p>\n";
    }
  }

  // locale
  if ( @file_exists( $loc_path ) ) {
    require $loc_path;
  } else {
    $locale['name'] = 'English';
  }
  if ( !isset( $l['controllers']['AuthCtl'] ) ) {

    $l['controllers']['AuthCtl']['title'] = 'Login';
    $l['controllers']['AuthCtl']['welcome'] = 'Welcome';
    $l['controllers']['AuthCtl']['email'] = 'email';
    $l['controllers']['AuthCtl']['password'] = '******';
    $l['controllers']['AuthCtl']['submit'] = 'Login';
    $l['controllers']['AuthCtl']['back'] = 'Back';
    $l['controllers']['AuthCtl']['exit'] = 'Exit';

    $nodes = tlalokes_str_from_array( $l );
    $nodes = preg_replace( '/^(\[.*)\n/m', "\$l$1\n", $nodes );

    $info = tlalokes_str_from_array( $locale );
    $info = preg_replace( '/^(\[.*)\n/m', "\$locale$1\n", $info );

    if ( !@file_put_contents( $loc_path, "<?\n$info\n$nodes", LOCK_EX ) ) {
      tlalokes_error_msg( "Builder: eng.php could not be generated", true );
    }
    echo "<p>English locale generated</p>\n";
  }
}
  public function generate ()
  {
    $controller = $this->conf['path']['app'].
                  $this->conf['path']['controllers'].$this->name . 'Ctl.php';
    $model = $this->conf['path']['app'].$this->conf['path']['bss'].
             $this->name . 'Bss.php';
    $view = $this->conf['path']['app'].$this->conf['path']['views'].
            strtolower( $this->name ) . '.tpl';
    $locale = $this->conf['path']['app'].$this->conf['path']['locales'].'eng.php';

    if ( !@file_put_contents( $controller, $this->getController(), LOCK_EX ) ) {
      tlalokes_error_msg( 'Builder: Cannot write '.$controller, true );
    }
    echo "<p>$this->name controller generated</p>\n";

    if ( !@file_put_contents( $model, $this->getModel(), LOCK_EX ) ) {
      tlalokes_error_msg( 'Builder: Cannot write '.$model, true );
    }
    echo "<p>$this->name model generated</p>\n";

    if ( !@file_put_contents( $view, $this->getView(), LOCK_EX ) ) {
      tlalokes_error_msg( 'Builder: Cannot write '.$view, true );
    }
    echo "<p>$this->name view generated</p>\n";

    if ( !@file_put_contents( $locale, $this->getLocale( $locale ), LOCK_EX ) ) {
      tlalokes_error_msg( 'Builder: Cannot write '.$locale, true );
    }
    echo "<p>English locale generated</p>\n";

    $head = $this->conf['path']['app'].'/'.$this->conf['path']['views'].'head.tpl';
    $foot = $this->conf['path']['app'].'/'.$this->conf['path']['views'].'foot.tpl';
    if ( !file_exists( $head ) ) {
      if ( !copy( $this->build_path.'views/head.tpl', $head ) ) {
        tlalokes_error_msg( "Builder: Cannot copy head.tpl", true );
      }
      echo "<p>Copied head.tpl</p>\n";
    }
    if ( !file_exists( $foot ) ) {
      if ( !copy( $this->build_path.'views/foot.tpl', $foot) ) {
        tlalokes_error_msg( "Builder: Cannot copy foot.tpl", true );
      }
      echo "<p>Copied foot.tpl</p>\n";
    }
  }
 /**
  * Compares two schemas and produces a SQL file to alterate tables
  * NOTE: This version only works for PostgreSQL
  *
  * @param TlalokesRegistry $reg
  * @todo check WARNINGS
  */
 private function buildAlterationFromSchemas(TlalokesRegistry $reg)
 {
     $r = '';
     $tmp = $reg->conf['path']['app'] . $reg->conf['path']['tmp'];
     // load db files
     $db = simplexml_load_file($tmp . 'generator/schema_from_db.xml');
     $df = simplexml_load_file($tmp . 'generator/schema_from_df.xml');
     // iterate tables
     foreach ($db->table as $db_table) {
         foreach ($df->table as $df_table) {
             // work on existant tables
             if ((string) $db_table['name'] == (string) $df_table['name']) {
                 // iterate columns
                 foreach ($df_table->column as $df_column) {
                     foreach ($db_table->column as $db_column) {
                         // work on existant columns
                         if ((string) $df_column['name'] == (string) $db_column['name']) {
                             // check size property
                             if (isset($df_column['size']) && !isset($db_column['size']) || (string) $df_column['size'] != (string) $db_column['size'] || isset($df_column['scale']) && !isset($db_column['scale'])) {
                                 // set scale
                                 $scale = isset($df_column['scale']) ? ',' . (string) $df_column['scale'] : '';
                                 // set size
                                 $size = '(' . (string) $df_column['size'] . "{$scale})";
                             }
                             // check type property
                             // WARNING: It needs to check types against
                             //          RDBMS via Creole Types. Right now
                             //          is using direct types from DefObjs
                             if (strtolower((string) $df_column['type']) != strtolower((string) $db_column['type']) || isset($size)) {
                                 // integer cannot have size
                                 if (isset($df_column['size']) && (string) $df_column['type'] == 'integer') {
                                     $e = 'Data type \'' . (string) $df_column['type'] . '\', specified for column \'' . (string) $df_column['name'] . '\', do not support size';
                                     tlalokes_error_msg($e);
                                 }
                                 // varchar cannot have scale
                                 if (isset($df_column['scale']) && (string) $df_column['type'] == 'varchar' || (string) $df_column['type'] == 'longvarchar') {
                                     $e = 'Data type ' . (string) $df_column['type'] . '\', specified for column \'' . (string) $df_column['name'] . '\', do not support scale';
                                     tlalokes_error_msg($e);
                                 }
                                 // WARNING: This is a horrible fix
                                 if ((string) $df_column['type'] == 'longvarchar') {
                                     $df_column['type'] = 'text';
                                 }
                                 // set alteration string
                                 $r .= 'ALTER TABLE ' . $df_table['name'] . ' ' . 'ALTER COLUMN ' . $df_column['name'] . ' ' . 'TYPE ' . (string) $df_column['type'];
                                 $r .= isset($df_column['size']) ? $size : '';
                                 $r .= ";\n";
                             }
                             // check required property
                             if (isset($db_column['required']) && !isset($df_column['required'])) {
                                 $r .= 'ALTER TABLE ' . $df_table['name'] . ' ALTER COLUMN ' . $df_column['name'] . " DROP NOT NULL;\n";
                             } elseif (isset($df_column['required']) && !isset($db_column['required'])) {
                                 $r .= 'ALTER TABLE ' . $df_table['name'] . ' ALTER COLUMN ' . $df_column['name'] . " SET NOT NULL;\n";
                             }
                             // check primaryKey property
                             if (isset($db_column['primaryKey']) && !isset($df_column['primaryKey'])) {
                                 $r .= 'ALTER TABLE ' . $df_table['name'] . ' ' . 'DROP CONSTRAINT ' . $df_table['name'] . "_pkey;\n";
                             } elseif (isset($df_column['primaryKey']) && !isset($db_column['primaryKey'])) {
                                 $r .= 'ALTER TABLE ' . $df_table['name'] . ' ' . 'ADD PRIMARY KEY (' . $df_column['name'] . ");\n";
                             }
                             unset($size);
                             // set new columns to add array
                         } elseif (!count($db_table->xpath('column[@name=\'' . $df_column['name'] . '\']'))) {
                             // add columns to array
                             $add_array[(string) $df_table['name']][(string) $df_column['name']] = $df_column;
                         }
                     }
                 }
                 // find index nodes in db
                 if (isset($db_table->index)) {
                     // iterate index nodes in db
                     foreach ($db_table->index as $db_index) {
                         foreach ($db_index->children() as $dbic) {
                             // set an array of existant indexes in db
                             $db_idx[(string) $dbic['name']] = (string) $db_index['name'];
                         }
                     }
                 }
                 // find index nodes in definition objects
                 if (isset($df_table->index)) {
                     static $i = 0;
                     // iterate index nodes in definition objects
                     foreach ($df_table->index as $df_index) {
                         $i++;
                         foreach ($df_index->children() as $dfic) {
                             // check if db have not an existant index
                             if (!isset($db_idx[(string) $dfic['name']])) {
                                 // set index creation string
                                 $r .= 'CREATE INDEX ' . (string) $df_table['name'] . '_i_' . $i . ' ON ' . (string) $df_table['name'] . ' (' . (string) $dfic['name'] . ");\n";
                             }
                         }
                     }
                 }
                 // find indexes to drop
                 if (isset($db_idx)) {
                     foreach ($db_idx as $db_idx_name => $db_idx_col) {
                         $xpath = "index/index-column[@name='{$db_idx_name}']";
                         if (!$df_table->xpath($xpath)) {
                             $r .= "DROP INDEX {$db_idx_col};\n";
                         }
                     }
                 }
                 // find unique nodes in db
                 if (isset($db_table->unique)) {
                     // iterate unique nodes in db
                     foreach ($db_table->unique as $db_unique) {
                         foreach ($db_unique->children() as $dbun) {
                             // set an array of existant uniques in db
                             $db_unq[(string) $dbun['name']] = (string) $db_unique['name'];
                         }
                     }
                 }
                 // find uniques nodes in definition objects
                 if (isset($df_table->unique)) {
                     $iu = count($db_unq);
                     // iterate unique nodes in definition objects
                     foreach ($df_table->unique as $df_unique) {
                         foreach ($df_unique->children() as $dfun) {
                             // check if db have not an existant unique
                             if (!isset($db_unq[(string) $dfun['name']])) {
                                 $iu++;
                                 // set unique creation string
                                 $r .= 'ALTER TABLE ' . (string) $df_table['name'] . ' ADD CONSTRAINT ' . (string) $df_table['name'] . "_u_{$iu} UNIQUE (" . (string) $dfun['name'] . ");\n";
                             }
                         }
                     }
                 }
                 // find uniques to drop
                 if (isset($db_unq)) {
                     foreach ($db_unq as $db_unq_name => $db_unq_col) {
                         $xpath = "unique/unique-column[@name='{$db_unq_name}']";
                         if (!$df_table->xpath($xpath)) {
                             $r .= "DROP CONSTRAINT {$db_unq_col};\n";
                         }
                     }
                 }
             }
         }
         // if there are new columns to add, do it
         if (isset($add_array)) {
             // iterate columns
             foreach ($add_array as $table => $column) {
                 foreach ($column as $col) {
                     // set scale
                     $scale = isset($col['scale']) ? ',' . (string) $col['scale'] : '';
                     // set size
                     $size = isset($col['size']) ? '(' . (string) $col['size'] . "{$scale})" : '';
                     // set null
                     $null = isset($col['required']) && $col['required'] == 'true' ? ' NOT NULL' : '';
                     // set primary key
                     $pkey = isset($col['primaryKey']) && $col['primaryKey'] == 'true' ? ' PRIMARY KEY' : '';
                     // set index
                     //$index  = isset( $col['index'] ) && $col['index'] == 'true'
                     //          ? 'CREATE INDEX ON ' : '';
                     //$index .= $table . '(' . $column['name'] . ");\n";
                     // varchar cannot have scale
                     if ((string) $col['type'] == 'varchar' || (string) $col['type'] == 'longvarchar' && isset($col['size'])) {
                         $e = 'Data type ' . (string) $col['type'] . ', in column \'' . (string) $df_column['name'] . '\', do not support size';
                         tlalokes_error_msg($e);
                     }
                     // WARNING: This is a horrible fix
                     if ((string) $col['type'] == 'longvarchar') {
                         $col['type'] = 'text';
                     }
                     // set response string
                     $r .= 'ALTER TABLE ' . $table . ' ADD COLUMN ' . (string) $col['name'] . ' ' . (string) $col['type'] . $size . $null . $pkey . ";\n";
                     //$r .= $index;
                     unset($size);
                 }
             }
         }
         // check if there are actions to apply
         if ($r) {
             // check sqldb.map directory existance
             $sql_dir = $tmp . 'generator/build/sql';
             if (!file_exists($sql_dir)) {
                 mkdir($sql_dir, 0770, true);
             }
             // write sql alterations file
             $sql_file = $sql_dir . '/def_obj_alt.sql';
             if (!file_put_contents($sql_file, $r)) {
                 tlalokes_error_msg('Cannot write ' . $sql_file);
             }
             // write a new sqldb.map file with file reference alteration
             $content = 'def_obj_alt.sql=' . $reg->conf['dsn']['name'] . "\n";
             if (!@file_put_contents($sql_dir . '/sqldb.map', $content)) {
                 tlalokes_error_msg('Propel: Cannot write ' . $sqldbmp_file, true);
             }
             return true;
         }
     }
 }
Beispiel #11
0
 /**
  * login action
  *
  * @ActionDefinition( file='tlalokes_auth.tpl' )
  */
 public function login ()
 {
   if ( !isset( $_SESSION['profiles'] ) || !isset( $_SESSION['role'] ) ) {
     // verify login
     if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
       // validate form
       if ( !isset( $_POST['email'] ) || !$_POST['email'] ) {
         $this->response->exception = 'Provide an email';
       } elseif ( !isset( $_POST['password'] ) || !$_POST['password'] ) {
         $this->response->exception = 'Provide a password';
       } else {
         // get file
         if ( !file_exists( $this->path['app'] . 'auth.php' ) ) {
           tlalokes_error_msg( 'Authentication: auth.php not found' );
         }
         require $this->path['app'] . 'auth.php';
         // check if account exists
         if ( !isset( $auth['users'][$this->request->email] ) ) {
           $this->response->exception = 'Invalid account';
         } else {
           // check password
           if ( $auth['users'][$this->request->email]['password'] ==
                md5( $this->request->password ) ) {
             // check role
             if ( !isset( $auth['users'][$this->request->email]['role'] ) ||
                  !$auth['users'][$this->request->email]['role'] ) {
               $this->response->exception = 'Your account has no role';
             } else {
               // get role
               $role = $auth['users'][$this->request->email]['role'];
               // check if role is enabled
               if ( !$auth['roles'][$role] ) {
                 $this->response->exception = 'Your role has been disabled';
               } else {
                 // set profiles
                 foreach ( $auth['profiles'] as $profile => $array ) {
                   foreach ( $array as $value ) {
                     if ( $value == $role ) {
                       $profiles[] = $profile;
                     }
                   }
                 }
                 if ( isset( $profiles ) && $profiles >= 1 ) {
                   $_SESSION['profiles'] = $profiles;
                   unset( $profiles );
                 }
                 // set role
                 $_SESSION['role'] = $role;
                 unset( $role );
                 // set welcome flag
                 $this->response->flag = true;
               }
             }
           } else {
             $this->response->exception = 'Password invalid try again';
           }
         }
       }
     }
   } else {
     $this->response->flag = true;
   }
 }
/**
 * Validates a property of an annotation object
 *
 * @author Basilio Briceno <*****@*****.**>
 * @param string $property
 * @param ReflectionClass $class
 */
function tlalokes_parser_annotation_valid($property, &$class)
{
    // check if property has key
    if (!strstr($property, '=')) {
        // remove garbage from property's value
        $property = preg_replace('/\\s*[\'|\\"]?([a-zA-Z0-9_-\\s]*)\\s[\'|\\"]?\\s*/', '$1', $property);
        return array($property, true);
        // check property's key
    } else {
        // remove spaces
        $property = str_replace(' = ', '=', $property);
        // get key and value
        list($key, $value) = explode('=', $property);
        // remove spaces
        $key = str_replace(' ', '', $key);
        // remove garbage from property's value
        $value = preg_replace('/\\s*[\'|\\"](.*)[\'|\\"]\\s*/', '$1', $value);
        $rc = new ReflectionClass($class);
        // validate property existance
        if (!$rc->hasProperty($key)) {
            tlalokes_error_msg('Annotations: No ' . $key . ' property.');
        }
        unset($rc);
        return array($key, $value);
    }
}
/**
 * Includes block files and set layout's response variables
 *
 * @param string $block
 * @param array $layout
 */
function tlalokes_layout_zone_block_include($block, &$layout)
{
    // if file extension found load it as is
    if (preg_match('/\\.(tpl|php)/', $block)) {
        $block = $layout['views_path'] . 'block/' . $block;
        if (!file_exists($block)) {
            tlalokes_error_msg('Layout: block file "' . $block . '" not found.');
        } else {
            // set local variables from TlalokesResponse
            if (isset($layout['response']) && $layout['response']) {
                var_dump($layout['response']);
                foreach ($layouẗ́['response'] as $key => $value) {
                    ${$key} = $value;
                }
            }
            include $block;
        }
        // load based in the layout name
    } else {
        $file = $layout['views_path'] . 'block/' . str_replace('layout.tpl', '', $layout['name']) . $block . '.tpl';
        if (!file_exists($file)) {
            tlalokes_error_msg('Layout: block file "' . $file . '" not found.');
        } else {
            // set local variables from TlalokesResponse
            if (isset($layout['response']) && $layout['response']) {
                foreach ($layout['response'] as $key => $value) {
                    ${$key} = $value;
                }
            }
            include $file;
        }
        unset($file);
    }
}
Beispiel #14
0
// check if execution is needed
tlalokes_core_execution($r, $c);
unset($c);
unset($uri);
unset($app);
unset($tlalokes);
// look up for controller
$path = $r->conf['path']['app'] . $r->conf['path']['controllers'];
if (!file_exists($path . $r->conf['current']['controller'] . '.php')) {
    if (!class_exists($r->conf['current']['controller'], false)) {
        $msg = 'Receiver: Class ' . $r->conf['current']['controller'] . ' not found.';
        tlalokes_error_msg($msg);
    }
}
unset($ctlr_path);
// check if request is for a web service
tlalokes_receiver_webservices($r);
// construct and load the controller
try {
    $load = new $r->conf['current']['controller']($r);
    unset($load);
} catch (Exception $e) {
    tlalokes_error_msg($e->getMessage());
}
// remove TlalokesRegistry
unset($r);
// print load time and end program
if (isset($tlalokes_load_time) && $tlalokes_load_time) {
    echo tlalokes_calculate_time_and_memory($start_time);
}
exit;
Beispiel #15
0
function tlalokes_setup_create_structure ( $tlalokes, $app, $post )
{
  if ( !file_exists( $app ) ) {
    if ( !@mkdir( $app ) ) {
      tlalokes_error_msg( 'Application path is not writeable' );
    }
  } else {
    mkdir( "$app/controller" );
    mkdir( "$app/model" );
    mkdir( "$app/model/business" );
    mkdir( "$app/model/dbo" );
    mkdir( "$app/model/dbo/def" );
    mkdir( "$app/view" );
    mkdir( "$app/_locale" );
    mkdir( "$app/_tmp" );
    mkdir( "$app/_tmp/cache" );
    mkdir( "$app/_tmp/compile" );
    mkdir( "$app/_tmp/generator" );
    if ( !tlalokes_setup_write_default_config( "$app/config.php", $post ) ) {
      tlalokes_error_msg( "Cannot create application's configuration file." );
    }
  }
  return true;
}
        $remote = $remote . '.tar';

        $file = @fopen( $remote, 'rb' );
        if ( !$file ) {
          throw new Exception( 'File not available or not connected.' );
        }
        fclose( $file );

        file_put_contents( $tmp_path, file_get_contents( $remote ) );
      }

      // execute tar on system
      $cmd = 'tar -xf '.$tmp_path.' -C '.$local;
      system( $cmd );
      if ( exec( 'ls -l '.$local.'/admin' ) == 'total 0' ) {
        tlalokes_error_msg( 'System error executing '.$cmd  );
      }
      unlink( $tmp_path );

      // rewrite the index file
      file_put_contents( $local.'/admin/index.php',
                         tlalokes_admin_get_index( $tlalokes, $app, $local ) );
?>
  <p>Congratulations, the admin application has been installed, to load it click
  <a href="<?=$uri;?>admin">here</a>.</p>
<?
    endif;

  else :
?>
  <p>You do not have the binary extension
 /**
  * Parses URI and sets the request values
  *
  * @param string $query_string
  */
 private function parseUri($query_string)
 {
     $uri = explode('/', $query_string);
     // controller
     if (isset($uri[0])) {
         $class = tlalokes_str_change_format($uri[0]) . 'Ctl';
         if (!class_exists($class)) {
             tlalokes_error_msg('Controller do not exist');
         }
         $this->_controller = $class;
     }
     // action
     $count = count($uri);
     if ($count > 1) {
         // clear action
         $rx = '/^([a-zA-Z0-9_\\-]*).*/';
         if (isset($uri[1])) {
             $uri[1] = preg_replace($rx, '$1', $uri[1]);
         }
         if (isset($uri[2])) {
             $uri[2] = preg_replace($rx, '$1', $uri[2]);
         }
         unset($rx);
         // set action
         if (method_exists($class, $uri[1])) {
             $this->_action = $uri[1];
         } elseif (isset($uri[2]) && method_exists($class, $uri[2])) {
             $this->_action = $uri[2];
             $this->_id = tlalokes_core_get_type($uri[1]);
         } elseif (isset($uri[1])) {
             $this->_id = tlalokes_core_get_type($uri[1]);
         }
     }
     // set action according to REST
     if (!isset($this->_action) || !$this->_action) {
         // set PUT
         if (isset($_POST) && $_POST && (!isset($this->_id) || !$this->_id)) {
             $this->_action = 'create';
             // set POST
         } elseif (isset($_POST) && $_POST && isset($this->_id)) {
             $this->_action = 'update';
             // set GET
         } elseif ((!isset($_POST) || !$_POST) && (!isset($this->_id) || isset($this->_id))) {
             $this->_action = 'read';
         }
     } else {
         // set DELETE
         if (!isset($_POST) && !$_POST && isset($this->_id) && $this->_action == 'delete') {
             $this->_action = 'delete';
         }
     }
     // aditional vars
     if ($count == 4) {
         $uri = array_slice($uri, 2);
     } elseif ($count >= 5) {
         if (isset($this->_action) && $this->_action == $uri[1]) {
             $uri = array_slice($uri, 2);
         } else {
             $uri = array_slice($uri, 3);
         }
     }
     if ($count >= 4) {
         for ($i = 0; $i < $count; ++$i) {
             if (isset($uri[$i])) {
                 $array[$i] = $uri[$i] . '=' . $uri[++$i];
             }
         }
         parse_str(implode('&', $array), $uri);
         // set new vars
         foreach ($uri as $key => $value) {
             if ($value) {
                 $this->{$key} = $value;
             }
         }
     }
 }
Beispiel #18
0
/**
 * Removes a directory in a recursive way
 *
 * @author Basilio Briceno <*****@*****.**>
 * @copyright Copyright (c) 2011, Basilio Briceno
 * @license http://www.gnu.org/licenses/lgpl.html GNU LGPL
 * @param string $path
 */
function tf_rmdir($path)
{
    if (!file_exists($path)) {
        tlalokes_error_msg('Directory provided not existant');
    }
    if (!is_writable($path)) {
        tlalokes_error_msg("Directory or file isn't writeable");
    }
    // check if $path is directory or file
    if (is_dir($path)) {
        // iterate $path directory
        foreach (glob($path . '/*') as $item) {
            // recursive call content in $item
            tf_rmdir($item);
        }
        // remove directory $path
        rmdir($path);
    } else {
        // remove file $path
        unlink($path);
    }
}