public function initialize()
 {
     $this->setDefaultProperties(array('classKey' => 'modSnippet', 'pk' => false));
     $tagParts = xPDO::escSplit('?', $this->getProperty('tag'), '`', 2);
     $tagNameParts = xPDO::escSplit('@', $tagParts[0]);
     $propertySet = isset($tagNameParts[1]) ? trim($tagNameParts[1]) : null;
     if (isset($propertySet) && strpos($propertySet, ':') != false) {
         $propSetParts = xPDO::escSplit(':', $propertySet);
         $propertySet = trim($propSetParts[0]);
     }
     if (isset($propertySet) && ($ps = $this->modx->getObject('modPropertySet', array('name' => $propertySet)))) {
         $this->setProperty('propertySet', $ps->id);
     }
     if (isset($tagParts[1])) {
         $tagPropString = ltrim(trim($tagParts[1]), '&');
         $this->tagProperties = $this->modx->getParser()->parseProperties($tagPropString);
     }
     //$this->modx->log(1,print_r($this->tagProperties,1));
     //$this->modx->log(modX::LOG_LEVEL_ERROR, $this->getProperty('tag'));
     $this->element = $this->modx->getObject($this->getProperty('classKey'), $this->getProperty('pk'));
     if (empty($this->element)) {
         return $this->modx->lexicon('element_err_nf');
     }
     return true;
 }
 public function processTag($tag, $processUncacheable = true)
 {
     // We need only # placeholders
     if ($tag[1][0] !== '#' && strpos($tag[1], '!#') === false) {
         return parent::processTag($tag, $processUncacheable);
     }
     $this->_processingTag = true;
     $element = null;
     $elementOutput = null;
     $outerTag = $tag[0];
     $innerTag = $tag[1];
     /* collect any nested element tags in the innerTag and process them */
     $this->processElementTags($outerTag, $innerTag, $processUncacheable);
     $this->_processingTag = true;
     $outerTag = '[[' . $innerTag . ']]';
     $tagParts = xPDO::escSplit('?', $innerTag, '`', 2);
     $tagName = trim($tagParts[0]);
     $tagPropString = null;
     if (isset($tagParts[1])) {
         $tagPropString = trim($tagParts[1]);
     }
     $token = substr($tagName, 0, 1);
     $tokenOffset = 0;
     $cacheable = true;
     if ($token === '!') {
         if (!$processUncacheable) {
             $this->_processingTag = false;
             return $outerTag;
         }
         $cacheable = false;
         $tokenOffset++;
         $token = substr($tagName, $tokenOffset, 1);
     }
     if ($cacheable && $token !== '+') {
         $elementOutput = $this->loadFromCache($outerTag);
     }
     if ($elementOutput === null) {
         switch ($token) {
             case '#':
                 include_once $this->modx->getOption('core_path') . 'components/fastfield/model/fastfield/fastfield.php';
                 $tagName = substr($tagName, 1 + $tokenOffset);
                 $element = new modResourceFieldTag($this->modx);
                 $element->set('name', $tagName);
                 $element->setTag($outerTag);
                 $element->setCacheable($cacheable);
                 $elementOutput = $element->process($tagPropString);
                 break;
         }
     }
     if (($elementOutput === null || $elementOutput === false) && $outerTag !== $tag[0]) {
         $elementOutput = $outerTag;
     }
     if ($this->modx->getDebug() === true) {
         $this->modx->log(xPDO::LOG_LEVEL_DEBUG, "Processing {$outerTag} as {$innerTag} using tagname {$tagName}:\n" . print_r($elementOutput, 1) . "\n\n");
     }
     $this->_processingTag = false;
     return $elementOutput;
 }
 /**
  * {@inheritDoc}
  * @return boolean
  */
 public function initialize()
 {
     $this->objectType = $this->getProperty('elementType');
     $this->classKey = 'mod' . ucfirst($this->objectType);
     $this->permission = 'view_' . $this->objectType;
     $tag = $this->getProperty('tag');
     $tagParts = xPDO::escSplit('?', $tag, '`', 2);
     $tagName = trim($tagParts[0]);
     $parser = $this->modx->getParser();
     $elementName = $this->elementName = $parser->realname($tagName);
     if (empty($elementName)) {
         return $this->modx->lexicon($this->objectType . '_err_ns');
     }
     $query = $this->modx->newQuery($this->classKey, array('name' => $elementName));
     $query->select('id');
     $id = $this->modx->getValue($query->prepare());
     if (!$id) {
         return $this->modx->lexicon($this->objectType . '_err_nf');
     }
     $this->setProperty('id', $id);
     return parent::initialize();
 }
 /**
  * Write an xPDO XML Schema from your database.
  *
  * @param string $schemaFile The name (including path) of the schemaFile you
  * want to write.
  * @param string $package Name of the package to generate the classes in.
  * @param string $baseClass The class which all classes in the package will
  * extend; by default this is set to {@link xPDOObject} and any
  * auto_increment fields with the column name 'id' will extend {@link
  * xPDOSimpleObject} automatically.
  * @param string $tablePrefix The table prefix for the current connection,
  * which will be removed from all of the generated class and table names.
  * Specify a prefix when creating a new {@link xPDO} instance to recreate
  * the tables with the same prefix, but still use the generic class names.
  * @param boolean $restrictPrefix Only reverse-engineer tables that have the
  * specified tablePrefix; if tablePrefix is empty, this is ignored.
  * @return boolean True on success, false on failure.
  */
 public function writeSchema($schemaFile, $package = '', $baseClass = '', $tablePrefix = '', $restrictPrefix = false)
 {
     if (empty($package)) {
         $package = $this->manager->xpdo->package;
     }
     if (empty($baseClass)) {
         $baseClass = 'xPDOObject';
     }
     if (empty($tablePrefix)) {
         $tablePrefix = $this->manager->xpdo->config[xPDO::OPT_TABLE_PREFIX];
     }
     $schemaVersion = xPDO::SCHEMA_VERSION;
     $xmlContent = array();
     $xmlContent[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
     $xmlContent[] = "<model package=\"{$package}\" baseClass=\"{$baseClass}\" platform=\"mysql\" defaultEngine=\"MyISAM\" version=\"{$schemaVersion}\">";
     //read list of tables
     $dbname = $this->manager->xpdo->escape($this->manager->xpdo->config['dbname']);
     $tableLike = $tablePrefix && $restrictPrefix ? " LIKE '{$tablePrefix}%'" : '';
     $tablesStmt = $this->manager->xpdo->prepare("SHOW TABLES FROM {$dbname}{$tableLike}");
     $tablesStmt->execute();
     $tables = $tablesStmt->fetchAll(PDO::FETCH_NUM);
     if ($this->manager->xpdo->getDebug() === true) {
         $this->manager->xpdo->log(xPDO::LOG_LEVEL_DEBUG, print_r($tables, true));
     }
     foreach ($tables as $table) {
         $xmlObject = array();
         $xmlFields = array();
         $xmlIndices = array();
         if (!($tableName = $this->getTableName($table[0], $tablePrefix, $restrictPrefix))) {
             continue;
         }
         $class = $this->getClassName($tableName);
         $extends = $baseClass;
         $fieldsStmt = $this->manager->xpdo->query('SHOW COLUMNS FROM ' . $this->manager->xpdo->escape($table[0]));
         if ($fieldsStmt) {
             $fields = $fieldsStmt->fetchAll(PDO::FETCH_ASSOC);
             if ($this->manager->xpdo->getDebug() === true) {
                 $this->manager->xpdo->log(xPDO::LOG_LEVEL_DEBUG, print_r($fields, true));
             }
             if (!empty($fields)) {
                 foreach ($fields as $field) {
                     $Field = '';
                     $Type = '';
                     $Null = '';
                     $Key = '';
                     $Default = '';
                     $Extra = '';
                     extract($field, EXTR_OVERWRITE);
                     $Type = xPDO::escSplit(' ', $Type, "'", 2);
                     $precisionPos = strpos($Type[0], '(');
                     $dbType = $precisionPos ? substr($Type[0], 0, $precisionPos) : $Type[0];
                     $dbType = strtolower($dbType);
                     $Precision = $precisionPos ? substr($Type[0], $precisionPos + 1, strrpos($Type[0], ')') - ($precisionPos + 1)) : '';
                     if (!empty($Precision)) {
                         $Precision = ' precision="' . trim($Precision) . '"';
                     }
                     $attributes = '';
                     if (isset($Type[1]) && !empty($Type[1])) {
                         $attributes = ' attributes="' . trim($Type[1]) . '"';
                     }
                     $PhpType = $this->manager->xpdo->driver->getPhpType($dbType);
                     $Null = ' null="' . ($Null === 'NO' ? 'false' : 'true') . '"';
                     $Key = $this->getIndex($Key);
                     $Default = $this->getDefault($Default);
                     if (!empty($Extra)) {
                         if ($Extra === 'auto_increment') {
                             if ($baseClass === 'xPDOObject' && $Field === 'id') {
                                 $extends = 'xPDOSimpleObject';
                                 continue;
                             } else {
                                 $Extra = ' generated="native"';
                             }
                         } else {
                             $Extra = ' extra="' . strtolower($Extra) . '"';
                         }
                         $Extra = ' ' . $Extra;
                     }
                     $xmlFields[] = "\t\t<field key=\"{$Field}\" dbtype=\"{$dbType}\"{$Precision}{$attributes} phptype=\"{$PhpType}\"{$Null}{$Default}{$Key}{$Extra} />";
                 }
             } else {
                 $this->manager->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'No columns were found in table ' . $table[0]);
             }
         } else {
             $this->manager->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Error retrieving columns for table ' . $table[0]);
         }
         $whereClause = $extends === 'xPDOSimpleObject' ? " WHERE `Key_name` != 'PRIMARY'" : '';
         $indexesStmt = $this->manager->xpdo->query('SHOW INDEXES FROM ' . $this->manager->xpdo->escape($table[0]) . $whereClause);
         if ($indexesStmt) {
             $indexes = $indexesStmt->fetchAll(PDO::FETCH_ASSOC);
             if ($this->manager->xpdo->getDebug() === true) {
                 $this->manager->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Indices for table {$table[0]}: " . print_r($indexes, true));
             }
             if (!empty($indexes)) {
                 $indices = array();
                 foreach ($indexes as $index) {
                     if (!array_key_exists($index['Key_name'], $indices)) {
                         $indices[$index['Key_name']] = array();
                     }
                     $indices[$index['Key_name']][$index['Seq_in_index']] = $index;
                 }
                 foreach ($indices as $index) {
                     $xmlIndexCols = array();
                     if ($this->manager->xpdo->getDebug() === true) {
                         $this->manager->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Details of index: " . print_r($index, true));
                     }
                     foreach ($index as $columnSeq => $column) {
                         if ($columnSeq == 1) {
                             $keyName = $column['Key_name'];
                             $primary = $keyName == 'PRIMARY' ? 'true' : 'false';
                             $unique = empty($column['Non_unique']) ? 'true' : 'false';
                             $packed = empty($column['Packed']) ? 'false' : 'true';
                             $type = $column['Index_type'];
                         }
                         $null = $column['Null'] == 'YES' ? 'true' : 'false';
                         $xmlIndexCols[] = "\t\t\t<column key=\"{$column['Column_name']}\" length=\"{$column['Sub_part']}\" collation=\"{$column['Collation']}\" null=\"{$null}\" />";
                     }
                     $xmlIndices[] = "\t\t<index alias=\"{$keyName}\" name=\"{$keyName}\" primary=\"{$primary}\" unique=\"{$unique}\" type=\"{$type}\" >";
                     $xmlIndices[] = implode("\n", $xmlIndexCols);
                     $xmlIndices[] = "\t\t</index>";
                 }
             } else {
                 $this->manager->xpdo->log(xPDO::LOG_LEVEL_WARN, 'No indexes were found in table ' . $table[0]);
             }
         } else {
             $this->manager->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Error getting indexes for table ' . $table[0]);
         }
         $xmlObject[] = "\t<object class=\"{$class}\" table=\"{$tableName}\" extends=\"{$extends}\">";
         $xmlObject[] = implode("\n", $xmlFields);
         if (!empty($xmlIndices)) {
             $xmlObject[] = '';
             $xmlObject[] = implode("\n", $xmlIndices);
         }
         $xmlObject[] = "\t</object>";
         $xmlContent[] = implode("\n", $xmlObject);
     }
     $xmlContent[] = "</model>";
     if ($this->manager->xpdo->getDebug() === true) {
         $this->manager->xpdo->log(xPDO::LOG_LEVEL_DEBUG, implode("\n", $xmlContent));
     }
     $file = fopen($schemaFile, 'wb');
     $written = fwrite($file, implode("\n", $xmlContent));
     fclose($file);
     return true;
 }
 /**
  * Gets a named property set related to this element instance.
  *
  * If a setName parameter is not provided, this function will attempt to
  * extract a setName from the element name using the @ symbol to delimit the
  * name of the property set.
  *
  * Here is an example of an element tag using the @ modifier to specify a
  * property set name:
  *  [[ElementName@PropertySetName:FilterCommand=`FilterModifier`?
  *      &PropertyKey1=`PropertyValue1`
  *      &PropertyKey2=`PropertyValue2`
  *  ]]
  *
  * @access public
  * @param string|null $setName An explicit property set name to search for.
  * @return array|null An array of properties or null if no set is found.
  */
 public function getPropertySet($setName = null)
 {
     $propertySet = null;
     $name = $this->get('name');
     if (strpos($name, '@') !== false) {
         $psName = '';
         $split = xPDO::escSplit('@', $name);
         if ($split && isset($split[1])) {
             $name = $split[0];
             $psName = $split[1];
             $filters = xPDO::escSplit(':', $setName);
             if ($filters && isset($filters[1]) && !empty($filters[1])) {
                 $psName = $filters[0];
                 $name .= ':' . $filters[1];
             }
             $this->set('name', $name);
         }
         if (!empty($psName)) {
             $psObj = $this->xpdo->getObjectGraph('modPropertySet', '{"Elements":{}}', array('Elements.element' => $this->id, 'Elements.element_class' => $this->_class, 'modPropertySet.name' => $psName));
             if ($psObj) {
                 $propertySet = $this->xpdo->parser->parseProperties($psObj->get('properties'));
             }
         }
     }
     if (!empty($setName)) {
         $propertySetObj = $this->xpdo->getObjectGraph('modPropertySet', '{"Elements":{}}', array('Elements.element' => $this->id, 'Elements.element_class' => $this->_class, 'modPropertySet.name' => $setName));
         if ($propertySetObj) {
             if (is_array($propertySet)) {
                 $propertySet = array_merge($propertySet, $this->xpdo->parser->parseProperties($propertySetObj->get('properties')));
             } else {
                 $propertySet = $this->xpdo->parser->parseProperties($propertySetObj->get('properties'));
             }
         }
     }
     return $propertySet;
 }
示例#6
0
 /**
  * Gets the real name of an element containing filter modifiers.
  *
  * @param string $unfiltered The unfiltered name of a {@link modElement}.
  * @return string The name minus any filter modifiers.
  */
 public function realname($unfiltered)
 {
     $filtered = $unfiltered;
     $split = xPDO::escSplit(':', $filtered);
     if ($split && isset($split[0])) {
         $filtered = $split[0];
         $propsetSplit = xPDO::escSplit('@', $filtered);
         if ($propsetSplit && isset($propsetSplit[0])) {
             $filtered = $propsetSplit[0];
         }
     }
     return $filtered;
 }
 public function getTablesToJson($baseClass = '', $tablePrefix = '', $restrictPrefix = false)
 {
     if (empty($baseClass)) {
         $baseClass = 'xPDOObject';
     }
     if (empty($tablePrefix)) {
         $tablePrefix = $this->manager->xpdo->config[xPDO::OPT_TABLE_PREFIX];
     }
     $jsonTables = array();
     //read list of tables
     $dbname = $this->databaseName;
     //$this->manager->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Database name: ' . $dbname);
     $tableLike = $tablePrefix && $restrictPrefix ? " LIKE '{$tablePrefix}%'" : '';
     $tablesStmt = $this->manager->xpdo->prepare("SHOW TABLES FROM {$dbname}{$tableLike}");
     $tablesStmt->execute();
     $tables = $tablesStmt->fetchAll(PDO::FETCH_NUM);
     if ($this->manager->xpdo->getDebug() === true) {
         $this->manager->xpdo->log(xPDO::LOG_LEVEL_DEBUG, print_r($tables, true));
     }
     foreach ($tables as $table) {
         $jsonFields = array();
         // the only thing added to this function the rest is copied:
         if (!in_array($table[0], $this->allowed_tables)) {
             //echo '<br>No Table: '.$table[0];
             //$this->manager->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'CMPGenerator->my_oPDO0->writeTableSchema -> No Table: '.$table[0]);
             continue;
         }
         //echo '<br>Table: '. $table[0];
         //$this->manager->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'CMPGenerator->my_oPDO0->writeTableSchema -> Table: '.$table[0].' - Pre: '.$tablePrefix.' - Restrict: '.$restrictPrefix );
         // End custom
         if (!($tableName = $this->getTableName($table[0], $tablePrefix, $restrictPrefix))) {
             continue;
         }
         $class = $this->getClassName($tableName);
         $extends = $baseClass;
         $sql = 'SHOW COLUMNS FROM ' . $this->manager->xpdo->escape($dbname) . '.' . $this->manager->xpdo->escape($table[0]);
         //$this->manager->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Line: '.__LINE__.' Sql: '.$sql);
         $fieldsStmt = $this->manager->xpdo->query($sql);
         if ($fieldsStmt) {
             $fields = $fieldsStmt->fetchAll(PDO::FETCH_ASSOC);
             if ($this->manager->xpdo->getDebug() === true) {
                 $this->manager->xpdo->log(xPDO::LOG_LEVEL_DEBUG, print_r($fields, true));
             }
             if (!empty($fields)) {
                 foreach ($fields as $field) {
                     $Field = '';
                     $Type = '';
                     $Null = '';
                     $Key = '';
                     $Default = '';
                     $Extra = '';
                     extract($field, EXTR_OVERWRITE);
                     $Type = xPDO::escSplit(' ', $Type, "'", 2);
                     $precisionPos = strpos($Type[0], '(');
                     $dbType = $precisionPos ? substr($Type[0], 0, $precisionPos) : $Type[0];
                     $dbType = strtolower($dbType);
                     $Precision = $precisionPos ? substr($Type[0], $precisionPos + 1, strrpos($Type[0], ')') - ($precisionPos + 1)) : '';
                     if (!empty($Precision)) {
                         $Precision = trim($Precision);
                     }
                     $attributes = '';
                     if (isset($Type[1]) && !empty($Type[1])) {
                         $attributes = trim($Type[1]);
                     }
                     $Null = ' null="' . ($Null === 'NO' ? 'false' : 'true') . '"';
                     $Key = $this->getIndex($Key);
                     $Default = $this->getDefault($Default);
                     $primaryKey = false;
                     if (!empty($Extra)) {
                         if ($Extra === 'auto_increment') {
                             $primaryKey = true;
                             if ($baseClass === 'xPDOObject' && $Field === 'id') {
                                 $extends = 'xPDOSimpleObject';
                                 //  continue;
                             } else {
                                 $Extra = ' generated="native"';
                             }
                         } else {
                             $Extra = ' extra="' . strtolower($Extra) . '"';
                         }
                         $Extra = ' ' . $Extra;
                     }
                     $type = !$Precision ? $dbType : $dbType . '(' . $Precision . ')';
                     $jsonFields[] = array('field' => $Field, 'type' => $type, 'key' => $primaryKey);
                 }
             } else {
                 $this->manager->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'No columns were found in table ' . $table[0]);
             }
         } else {
             $this->manager->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Error retrieving columns for table ' . $table[0]);
         }
         $jsonTables[$tableName] = $jsonFields;
     }
     if ($this->manager->xpdo->getDebug() === true) {
         $this->manager->xpdo->log(xPDO::LOG_LEVEL_DEBUG, print_r($jsonTables, 1));
     }
     return $jsonTables;
 }
示例#8
0
 /**
  * Test xPDO::escSplit
  */
 public function testEscSplit()
 {
     if (!empty(xPDOTestHarness::$debug)) {
         print "\n" . __METHOD__ . " = ";
     }
     $str = '1,2,3';
     $result = xPDO::escSplit(',', $str, $this->xpdo->_escapeCharOpen);
     $this->assertTrue(is_array($result), 'xPDO::escSplit did not return an array.');
     $this->assertEquals(3, count($result), 'xPDO::escSplit did not return the correct number of indices.');
 }
示例#9
0
 /**
  * Write an XPDO XML Schema from your database.
  *
  * @param string $schemaFile The name (including path) of the schemaFile you
  * want to write.
  * @param string $package Name of the package to generate the classes in.
  * @param string $baseClass The class which all classes in the package will
  * extend; by default this is set to {@link xPDOObject} and any
  * auto_increment fields with the column name 'id' will extend {@link
  * xPDOSimpleObject} automatically.
  * @param string $tablePrefix The table prefix for the current connection,
  * which will be removed from all of the generated class and table names.
  * Specify a prefix when creating a new {@link xPDO} instance to recreate
  * the tables with the same prefix, but still use the generic class names.
  * @param boolean $restrictPrefix Only reverse-engineer tables that have the
  * specified tablePrefix; if tablePrefix is empty, this is ignored.
  * @return boolean True on success, false on failure.
  */
 public function writeSchema($schemaFile, $package = '', $baseClass = '', $tablePrefix = '', $restrictPrefix = false)
 {
     if (empty($package)) {
         $package = $this->manager->xpdo->package;
     }
     if (empty($baseClass)) {
         $baseClass = 'xPDOObject';
     }
     if (empty($tablePrefix)) {
         $tablePrefix = $this->manager->xpdo->config[xPDO::OPT_TABLE_PREFIX];
     }
     $xmlContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     $xmlContent .= "<model package=\"{$package}\" baseClass=\"{$baseClass}\" platform=\"mysql\" defaultEngine=\"MyISAM\">\n";
     //read list of tables
     $dbname = $this->manager->xpdo->config['dbname'];
     $tableLike = $tablePrefix && $restrictPrefix ? " LIKE '{$tablePrefix}%'" : '';
     $tablesStmt = $this->manager->xpdo->prepare("SHOW TABLES FROM {$dbname}{$tableLike}");
     $tablesStmt->execute();
     $tables = $tablesStmt->fetchAll(PDO::FETCH_NUM);
     if ($this->manager->xpdo->getDebug() === true) {
         $this->manager->xpdo->log(xPDO::LOG_LEVEL_DEBUG, print_r($tables, true));
     }
     foreach ($tables as $table) {
         $xmlObject = '';
         $xmlFields = '';
         if (!($tableName = $this->getTableName($table[0], $tablePrefix, $restrictPrefix))) {
             continue;
         }
         $class = $this->getClassName($tableName);
         $extends = $baseClass;
         $fieldsStmt = $this->manager->xpdo->prepare("SHOW COLUMNS FROM `{$table[0]}`");
         $fieldsStmt->execute();
         $fields = $fieldsStmt->fetchAll(PDO::FETCH_ASSOC);
         if ($this->manager->xpdo->getDebug() === true) {
             $this->manager->xpdo->log(xPDO::LOG_LEVEL_DEBUG, print_r($fields, true));
         }
         foreach ($fields as $field) {
             $Field = '';
             $Type = '';
             $Null = '';
             $Key = '';
             $Default = '';
             $Extra = '';
             extract($field, EXTR_OVERWRITE);
             $Type = xPDO::escSplit(' ', $Type, "'", 2);
             $precisionPos = strpos($Type[0], '(');
             $dbType = $precisionPos ? substr($Type[0], 0, $precisionPos) : $Type[0];
             $dbType = strtolower($dbType);
             $Precision = $precisionPos ? substr($Type[0], $precisionPos + 1, strrpos($Type[0], ')') - ($precisionPos + 1)) : '';
             if (!empty($Precision)) {
                 $Precision = ' precision="' . trim($Precision) . '"';
             }
             $attributes = '';
             if (isset($Type[1]) && !empty($Type[1])) {
                 $attributes = ' attributes="' . trim($Type[1]) . '"';
             }
             $PhpType = $this->getPhpType($dbType);
             $Null = ' null="' . ($Null === 'NO' ? 'false' : 'true') . '"';
             $Key = $this->getIndex($Key);
             $Default = $this->getDefault($Default);
             if (!empty($Extra)) {
                 if ($Extra === 'auto_increment') {
                     if ($baseClass === 'xPDOObject' && $Field === 'id') {
                         $extends = 'xPDOSimpleObject';
                         continue;
                     } else {
                         $Extra = ' generated="native"';
                     }
                 } else {
                     $Extra = ' extra="' . strtolower($Extra) . '"';
                 }
                 $Extra = ' ' . $Extra;
             }
             $xmlFields .= "\t\t<field key=\"{$Field}\" dbtype=\"{$dbType}\"{$Precision}{$attributes} phptype=\"{$PhpType}\"{$Null}{$Default}{$Key}{$Extra} />\n";
             //                echo $xmlContent . "\n";
         }
         $xmlObject .= "\t<object class=\"{$class}\" table=\"{$tableName}\" extends=\"{$extends}\">\n";
         $xmlObject .= $xmlFields;
         $xmlObject .= "\t</object>\n";
         $xmlContent .= $xmlObject;
     }
     $xmlContent .= "</model>\n";
     if ($this->manager->xpdo->getDebug() === true) {
         $this->manager->xpdo->log(xPDO::LOG_LEVEL_DEBUG, $xmlContent);
     }
     $file = fopen($schemaFile, 'wb');
     $written = fwrite($file, $xmlContent);
     fclose($file);
     return true;
 }
示例#10
0
 /**
  * @param string $content
  * @param array $tags
  */
 public function findTags($content, &$tags)
 {
     $parser = $this->modx->getParser();
     $collectedTags = array();
     $parser->collectElementTags($content, $collectedTags);
     foreach ($collectedTags as $tag) {
         $tagName = $tag[1];
         if (substr($tagName, 0, 1) == '!') {
             $tagName = substr($tagName, 1);
         }
         $token = substr($tagName, 0, 1);
         $tagParts = xPDO::escSplit('?', $tagName, '`', 2);
         $tagName = trim($tagParts[0]);
         $tagPropString = null;
         $tagName = trim($this->modx->stripTags($tagName));
         if (in_array($token, array('$', '+', '~', '#', '%', '-', '*'))) {
             $tagName = substr($tagName, 1);
         }
         switch ($token) {
             case '$':
                 $class = 'modChunk';
                 break;
             case '+':
             case '~':
             case '#':
             case '%':
             case '-':
             case '*':
                 continue 2;
                 break;
             default:
                 $class = 'modSnippet';
                 break;
         }
         if (isset($tagParts[1])) {
             $tagPropString = trim($tagParts[1]);
             $this->findTags($tagPropString, $tags);
             $element = $parser->getElement($class, $tagName);
             if ($element) {
                 $properties = $element->getProperties($tagPropString);
             } else {
                 $properties = array();
             }
         } else {
             $properties = array();
         }
         $this->debug('Found ' . $class . ' ' . $tagName . ' with properties ' . print_r($properties, 1));
         $tagName = $parser->realname($tagName);
         if (empty($tagName)) {
             continue;
         }
         $tags[$tagName] = array('name' => $tagName, 'class' => $class);
         foreach ($properties as $property) {
             $prop = trim($property);
             if (!empty($prop) && !is_numeric($prop) && is_string($prop)) {
                 $tags[$prop] = array('name' => $prop, 'class' => 'modChunk', 'isProperty' => true);
             }
         }
     }
 }
示例#11
0
 public function processTag($tag, $processUncacheable = true)
 {
     $this->_processingTag = true;
     $element = null;
     $elementOutput = null;
     $outerTag = $tag[0];
     $innerTag = $tag[1];
     /* Avoid all processing for comment tags, e.g. [[- comments here]] */
     if (substr($innerTag, 0, 1) === '-') {
         return "";
     }
     /* collect any nested element tags in the innerTag and process them */
     $this->processElementTags($outerTag, $innerTag, $processUncacheable);
     $this->_processingTag = true;
     $outerTag = '[[' . $innerTag . ']]';
     $tagParts = xPDO::escSplit('?', $innerTag, '`', 2);
     $tagName = trim($tagParts[0]);
     $tagPropString = null;
     if (isset($tagParts[1])) {
         $tagPropString = trim($tagParts[1]);
     }
     $token = substr($tagName, 0, 1);
     $tokenOffset = 0;
     $cacheable = true;
     if ($token === '!') {
         if (!$processUncacheable) {
             $this->_processingTag = false;
             return $outerTag;
         }
         $cacheable = false;
         $tokenOffset++;
         $token = substr($tagName, $tokenOffset, 1);
     }
     if ($cacheable && $token !== '+') {
         $elementOutput = $this->loadFromCache($outerTag);
     }
     if ($elementOutput === null) {
         switch ($token) {
             case '+':
                 $tagName = substr($tagName, 1 + $tokenOffset);
                 $element = new modPlaceholderTag($this->modx);
                 $element->set('name', $tagName);
                 $element->setTag($outerTag);
                 $elementOutput = $element->process($tagPropString);
                 break;
             case '%':
                 $tagName = substr($tagName, 1 + $tokenOffset);
                 $element = new modLexiconTag($this->modx);
                 $element->set('name', $tagName);
                 $element->setTag($outerTag);
                 $element->setCacheable($cacheable);
                 $elementOutput = $element->process($tagPropString);
                 break;
             case '~':
                 // replace modLinkTag with ShopmodxLinkTag
                 $tagName = substr($tagName, 1 + $tokenOffset);
                 $element = new ShopmodxLinkTag($this->modx);
                 $element->set('name', $tagName);
                 $element->setTag($outerTag);
                 $element->setCacheable($cacheable);
                 $elementOutput = $element->process($tagPropString);
                 break;
             case '$':
                 $tagName = substr($tagName, 1 + $tokenOffset);
                 if ($element = $this->getElement('modChunk', $tagName)) {
                     $element->set('name', $tagName);
                     $element->setTag($outerTag);
                     $element->setCacheable($cacheable);
                     $elementOutput = $element->process($tagPropString);
                 }
                 break;
             case '*':
                 $tagName = substr($tagName, 1 + $tokenOffset);
                 $nextToken = substr($tagName, 0, 1);
                 if ($nextToken === '#') {
                     $tagName = substr($tagName, 1);
                 }
                 if (is_array($this->modx->resource->_fieldMeta) && in_array($this->realname($tagName), array_keys($this->modx->resource->_fieldMeta))) {
                     $element = new modFieldTag($this->modx);
                     $element->set('name', $tagName);
                     $element->setTag($outerTag);
                     $element->setCacheable($cacheable);
                     $elementOutput = $element->process($tagPropString);
                 } elseif ($element = $this->getElement('modTemplateVar', $tagName)) {
                     $element->set('name', $tagName);
                     $element->setTag($outerTag);
                     $element->setCacheable($cacheable);
                     $elementOutput = $element->process($tagPropString);
                 }
                 break;
             default:
                 $tagName = substr($tagName, $tokenOffset);
                 if ($element = $this->getElement('modSnippet', $tagName)) {
                     $element->set('name', $tagName);
                     $element->setTag($outerTag);
                     $element->setCacheable($cacheable);
                     $elementOutput = $element->process($tagPropString);
                 }
         }
     }
     if (($elementOutput === null || $elementOutput === false) && $outerTag !== $tag[0]) {
         $elementOutput = $outerTag;
     }
     if ($this->modx->getDebug() === true) {
         $this->modx->log(xPDO::LOG_LEVEL_DEBUG, "Processing {$outerTag} as {$innerTag} using tagname {$tagName}:\n" . print_r($elementOutput, 1) . "\n\n");
         /* $this->modx->cacheManager->writeFile(MODX_BASE_PATH . 'parser.log', "Processing {$outerTag} as {$innerTag}:\n" . print_r($elementOutput, 1) . "\n\n", 'a'); */
     }
     $this->_processingTag = false;
     return $elementOutput;
 }