Ejemplo n.º 1
0
 public function load()
 {
     $this->_data = array();
     $host = 'http://' . $_SERVER['SERVER_NAME'];
     // This will retrieve all the content pages.
     if (Typeframe::Registry()->application('Content')) {
         $query = "SELECT uri, nickname,\tapplication FROM #__page";
         $rs = Typeframe::Database()->prepare($query);
         $rs->execute();
         while ($data = $rs->fetch_array()) {
             $this->_data[] = array('page' => $host . TYPEF_WEB_DIR . $data['uri'], 'uri' => $data['uri'], 'name' => $data['nickname'] != '' ? $data['nickname'] : $data['uri'], 'application' => $data['application']);
         }
     }
     // And the news pages.
     if (Typeframe::Registry()->application('News')) {
         $select = new BuildSql_Select();
         $select->table('#__news n');
         $select->leftJoin('#__news_category ncat', 'ncat.categoryid = n.categoryid');
         $select->field('n.*');
         $select->field('ncat.categoryname');
         $select->group('n.newsid');
         $select->order('n.pubdate DESC');
         $select->where('n.pubdate <= ?', Typeframe::Now());
         $rs = $this->db()->prepare($select->query());
         $rs->execute();
         while ($row = $rs->fetch_array()) {
             $uri = News::GetCategoryUri($row['categoryid']) . '/' . ($row['encodedtitle'] ? $row['encodedtitle'] : $row['newsid']);
             $this->_data[] = array('page' => $host . TYPEF_WEB_DIR . $uri, 'uri' => $uri, 'name' => $row['title'], 'application' => $row['categoryname']);
         }
     }
 }
Ejemplo n.º 2
0
 public function output(PMDataNode $data)
 {
     $pm = new Pagemill($data->fork());
     //$pm->setVariableArray($this->settings);
     $db = Typeframe::Database();
     if (!isset($this->settings['driver'])) {
         //return '<div class="error"><p>Please provide a "driver" attribute on the pm:driver plugin.</p></div>';
         return '';
     }
     // Blank driver attributes count as nothing too.
     if (!$this->settings['driver']) {
         return '';
     }
     // I need to lookup this driver as a page and ensure it's a valid driver.
     $driver = (int) $this->settings['driver'];
     $rs = $db->prepare('SELECT uri, nickname, driver FROM #__page WHERE driver != "" AND pageid = ?');
     $rs->execute($driver);
     if (!$rs->recordcount()) {
         // No records found... just silently fail.
         return '';
     }
     $data = $rs->fetch_array();
     $pm->setVariable('link', TYPEF_WEB_DIR . $data['uri']);
     $pm->setVariable('title', $data['nickname']);
     $pm->setVariable('driver', $data['driver']);
     return $pm->writeText('<pm:include template="/plugins/driver.html" />');
 }
Ejemplo n.º 3
0
 public function output(Pagemill_Data $data, Pagemill_Stream $stream)
 {
     $db = Typeframe::Database();
     if ($this->hasAttribute('rules') && !Typeframe_Tag_Socket::ProcessRules($this->getAttribute('rules'))) {
         return '';
     }
     /*
      * Rules for loading the plugin:
      * 1. The plugid overrides other load settings.
      * 2. Load a plugin from the table if the name attribute matches an
      *    an admin-specified name.
      * 3. Create a generic plugin from a signature.
      * 4. If the plugin was loaded from the database, attribute settings
      *    override database settings.
      */
     $p = null;
     if ($this->getAttribute('plugid')) {
         $plugin = Model_Plug::Get($data->parseVariables($this->getAttribute('plugid')));
         if ($plugin->exists()) {
             $p = Typeframe::Registry()->getPluginSignature($plugin['plug']);
         }
     } else {
         if ($this->getAttribute('name')) {
             $plugins = new Model_Plug();
             $plugins->where('name = ?', $data->parseVariables($this->getAttribute('name')));
             $plugin = $plugins->getFirst();
             if ($plugin->exists()) {
                 $p = Typeframe::Registry()->getPluginSignature($plugin['plug']);
             } else {
                 $p = Typeframe::Registry()->getPluginSignature($this->getAttribute('name'));
             }
         }
     }
     if ($p) {
         $cls = $p->className();
         if (class_exists($cls)) {
             $settings = $this->settings;
             foreach ($this->attributes() as $k => $v) {
                 $settings[$k] = $data->parseVariables($v);
             }
             //$obj = new $cls($settings);
             $obj = new $cls('plugin', $settings, null);
             foreach ($this->children() as $child) {
                 $obj->appendChild($child);
             }
             $obj->process($data, $stream);
             foreach ($obj->children() as $child) {
                 $this->appendChild($child);
             }
             $obj->detach();
         } else {
             throw new Exception("Class '{$cls}' does not exist");
         }
     } else {
         throw new Exception("Plugin does not have a signature");
     }
 }
Ejemplo n.º 4
0
 public function output(Pagemill_Data $data, Pagemill_Stream $stream)
 {
     $data = $data->fork();
     if (!empty($this->attributes['menuplugid'])) {
         $menuplugid = $this->attributes['menuplugid'];
         $db = Typeframe::Database();
         $base = substr(Typeframe::CurrentPage()->uri(), STRLEN(TYPEF_WEB_DIR));
         if ($base == '') {
             $base = '/';
         }
         $search = new Model_Nav();
         $search->where('plugid = ?', $menuplugid);
         $search->where('url = ? OR url = ? OR url = ? OR url = ? OR url = ? OR url = ? OR pageid = ?', "~{$base}", "~{$base}/", "/{$base}", "/{$base}/", TYPEF_WEB_DIR . $base, TYPEF_WEB_DIR . $base . '/', Typeframe::CurrentPage()->pageid());
         foreach ($search->select() as $current) {
             $current['url'] = $this->_convertUrl($current['url']);
             $data->set('current', $current);
             $parentid = $current['parent'];
             $siblings = new Model_Nav();
             $siblings->where('plugid = ?', $menuplugid);
             $siblings->where('parent = ?', $parentid);
             $siblings->order('sortnum');
             $data['siblings'] = $siblings;
             /*$sibArray = array();
             		foreach ($siblings->select() as $sib) {
             			$sib['url'] = $this->_convertUrl($sib['url']);
             			$sibArray[] = $sib;
             		}
             		$data['siblings'] = $sibArray;*/
             if (!empty($this->attributes['showparent'])) {
                 $parent = $db->execute('SELECT * FROM #__nav WHERE itemid = ' . $parentid);
                 foreach ($parent as $par) {
                     $par['url'] = $this->_convertUrl($par['url']);
                     $data->set('parent', $par);
                 }
             }
             if (!empty($this->attributes['showchildren'])) {
                 $childArray = array();
                 $children = $db->execute('SELECT * FROM #__nav WHERE plugid = ' . $menuplugid . ' AND parent = ' . $current['itemid'] . ' ORDER BY sortnum');
                 foreach ($children as $chi) {
                     $chi['url'] = $this->_convertUrl($chi['url']);
                     $childArray[] = $chi;
                 }
                 $data['children'] = $childArray;
             }
         }
     }
     $this->pluginTemplate = "navigation/submenu.plug.html";
     parent::output($data, $stream);
 }
Ejemplo n.º 5
0
Archivo: Admin.php Proyecto: ssrsfs/blg
 public function allow()
 {
     if (!Typeframe::User()->loggedIn()) {
         return false;
     }
     if (Typeframe::User()->get('usergroupid') == TYPEF_ADMIN_USERGROUPID) {
         return true;
     }
     $relativeUri = substr($this->page()->uri(), strlen(TYPEF_WEB_DIR));
     if ($relativeUri == '/admin' || $relativeUri == '/admin/') {
         // Main admin page.  Just check to see if the user has access to any other applications.
         $rs = Typeframe::Database()->execute('SELECT * FROM #__usergroup_admin WHERE usergroupid = ' . Typeframe::User()->get('usergroupid'));
         return count($rs) > 0;
     }
     $rs = Typeframe::Database()->execute('SELECT * FROM #__usergroup_admin WHERE usergroupid = ' . Typeframe::User()->get('usergroupid') . ' AND application = \'' . $this->page()->application()->name() . '\'');
     return $rs->count() > 0;
 }
Ejemplo n.º 6
0
function makeFriendlyUrlText($string, $query = null)
{
    // DO NOT pass an entire URL into this function.  It'll just get mangled.
    // Pass text that needs to be made friendly for insertion into a path, such as the
    // title of an article.
    $result = strtolower($string);
    $result = str_replace("'", '', $result);
    $result = preg_replace('/[^a-z0-9]+/', '-', $result);
    $result = preg_replace('/[\\-]+/', '-', $result);
    // Maximum length for each unit (assumed here to be used as a single directory name)
    // is 60 characters, plus a numeric ID in the case of duplicated titles
    if (strlen($result) > 60) {
        $result = substr($result, 0, 100);
        if (substr($result, 59) == '-') {
            $result = substr($result, 0, 99);
        }
    }
    if ($result[0] == '-') {
        $result = substr($result, 1);
    }
    if (substr($result, strlen($result) - 1) == '-') {
        $result = substr($result, 0, strlen($result) - 1);
    }
    if (!is_null($query)) {
        // Make sure the text does not already exist in the specified query
        // The query should include a parameter for the text (e.g.: SELECT * FROM table WHERE url = ?)
        $rs = Typeframe::Database()->prepare($query);
        $checked = $result;
        $num = 0;
        $rs->execute($checked);
        while ($rs->recordcount() > 0) {
            $num++;
            $checked = $result . '-' . $num;
            $rs->execute($checked);
        }
        $result = $checked;
    }
    return $result;
}
Ejemplo n.º 7
0
 /**
  * Include (evaluate) a file in the source/scripts directory.
  * @param string $script The relative path to the file.
  */
 public static function IncludeScript($script)
 {
     // TODO: Get rid of these variables.  They should be declared explicitly in the controller if necessary.
     $pm = Typeframe::Pagemill();
     $db = Typeframe::Database();
     include_once TYPEF_SOURCE_DIR . '/scripts' . $script;
 }
Ejemplo n.º 8
0
Archivo: index.php Proyecto: ssrsfs/blg
<?php

$db = Typeframe::Database();
$pm = Typeframe::Pagemill();
Typeframe::SetPageTemplate('/admin/applications/index.html');
foreach (Typeframe::Registry()->applications() as $a) {
    $app = array('name' => $a->name(), 'title' => $a->title(), 'map' => $a->map());
    $pm->addLoop('applications', $app);
    if ($a->map() == 'hard') {
        $pm->addLoop('applications', 'pages', array('uri' => TYPEF_WEB_DIR . $a->base()));
    } else {
        // TODO: Figure out what to do about soft-mapped pages
        /*
        foreach (Typeframe::Registry()->getApplicationPagesByName($a->name()) as $p) {
        	$pm->addLoop('applications', 'pages', array('uri' => $p->uri()));
        }
        */
    }
}
$pm->sortLoop('applications', 'name');
Ejemplo n.º 9
0
 private static function _Include($file, Pagemill $pm)
 {
     $db = Typeframe::Database();
     include $file;
 }
Ejemplo n.º 10
0
 private static function _IncludeController($filename)
 {
     // TODO: Get rid of these variables.  They should be declared explicitly in the controller if necessary.
     $pm = Typeframe::Pagemill();
     $db = Typeframe::Database();
     include $filename;
 }
Ejemplo n.º 11
0
     if ($column['Extra'] == 'auto_increment') {
         $autoIncrement = true;
     }
     $xlate = array();
     $xlate['name'] = $column['Field'];
     /*if (substr($column['Type'], 0, 3) == 'int') {
     			// integer
     		} else if (substr($column['Type'], 0, 7) == 'varchar') {
     			// varchar
     		}*/
     $xlate['type'] = addslashes($column['Type']);
     $xlate['allownull'] = $column['Null'] == 'NO' ? false : true;
     $xlate['defaultvalue'] = $column['Default'];
     $columns[] = $xlate;
 }
 $rsIndexes = Typeframe::Database()->execute('SHOW INDEX IN ' . $tableName);
 $indexes = array();
 foreach ($rsIndexes as $index) {
     $name = strtolower($index['Key_name']);
     if (!isset($indexes[$name])) {
         $indexes[$name] = array();
         $indexes[$name]['name'] = $name;
         $indexes[$name]['unique'] = $index['Non_unique'] == 0 ? true : false;
         $indexes[$name]['columns'] = array();
     }
     $indexes[$name]['columns'][] = array('name' => $index['Column_name']);
 }
 $classMill = new Pagemill();
 $classMill->setVariable('class', $className);
 $classMill->setVariable('table', $shortName);
 $classMill->setVariable('prefix', $prefix);
Ejemplo n.º 12
0
Archivo: Menu.php Proyecto: ssrsfs/blg
 public function update(array $input = null)
 {
     //gimme life!
     //$item = isset($_POST['itemid']) ? new Navigation_Item($_POST['itemid']) : new Navigation_Item();
     $item = isset($_POST['itemid']) && !is_array($_POST['itemid']) ? Model_Nav::Get($_POST['itemid']) : Model_Nav::Create();
     if ($_REQUEST['cmd'] != 'delete' && $_REQUEST['cmd'] != 'name' && $_REQUEST['cmd'] != 'sort') {
         $item->set('pageid', 0);
         switch ($_POST['type']) {
             case 'none':
                 // Heh, these have no extra attributes, so null just about everything.
                 $item->set('label', $_POST['label']);
                 $item->set('url', '');
                 $item->set('onclick', '');
                 $item->set('visibility', 'always');
                 $item->set('method', '');
                 $item->set('target', '');
                 break;
             case 'int':
                 $item->set('label', $_POST['label']);
                 $item->set('pageid', $_POST['pageid']);
                 $item->set('url', '');
                 $item->set('onclick', '');
                 $item->set('visibility', 'permitted');
                 $item->set('method', $_POST['method']);
                 $item->set('target', $_POST['target']);
                 break;
             case 'arbint':
                 $item->set('label', $_POST['label']);
                 $item->set('url', $_POST['url']);
                 $item->set('onclick', '');
                 $item->set('visibility', $_POST['visibility']);
                 $item->set('method', $_POST['method']);
                 $item->set('target', $_POST['target']);
                 break;
             case 'ext':
                 $item->set('label', $_POST['label']);
                 $item->set('url', $_POST['url']);
                 $item->set('onclick', '');
                 $item->set('visibility', $_POST['visibility']);
                 $item->set('method', $_POST['method']);
                 $item->set('target', $_POST['target']);
                 break;
             case 'mailto':
                 $item->set('label', $_POST['label']);
                 $item->set('url', 'mailto:' . $_POST['url']);
                 $item->set('onclick', '');
                 $item->set('visibility', $_POST['visibility']);
                 $item->set('method', '');
                 $item->set('target', '');
                 break;
         }
     }
     switch ($_REQUEST['cmd']) {
         case 'add':
             $item->set('parent', $_POST['parent']);
             $item->set('plugid', $_POST['plugid']);
             $result = Typeframe::Database()->execute('SELECT MAX(sortnum) AS maxsort FROM #__nav WHERE plugid = ' . (int) $_POST['plugid']);
             $max = $result[0];
             $item->set('sortnum', $max['maxsort'] + 1);
             $item->save();
             $msg = " Added";
             break;
         case 'edit':
             $item->save();
             $msg = " Saved";
             break;
         case 'delete':
             $item->delete();
             $msg = " Deleted";
             break;
         case 'name':
             $plug = Model_Plug::Get($_POST['plugid']);
             $plug['name'] = $_POST['name'];
             $plug->save();
             Typeframe::Redirect('Name updated.', Typeframe::CurrentPage()->applicationUri() . '/edit?plugid=' . $_POST['plugid'] . '&parentid=' . (isset($_POST['parentid']) ? $_POST['parentid'] : '0'));
             return;
         case 'sort':
             $sortnum = 1;
             for ($i = 0; $i < count($_POST['itemid']); $i++) {
                 $item = Model_Nav::Get($_POST['itemid'][$i]);
                 $item['parent'] = $_POST['parent'][$i];
                 $item['sortnum'] = $sortnum;
                 $item->save();
                 $sortnum++;
             }
             Typeframe::Redirect('Items sorted.', Typeframe::CurrentPage()->applicationUri() . '/edit?plugid=' . $_POST['plugid'] . '&parentid=' . (isset($_POST['parentid']) ? $_POST['parentid'] : '0'));
             return;
     }
     Typeframe::Redirect('Item' . $msg, Typeframe::CurrentPage()->applicationUri() . '/edit?plugid=' . $_POST['plugid'] . '&parentid=' . (isset($_POST['parentid']) ? $_POST['parentid'] : '0'));
 }
Ejemplo n.º 13
0
        $pathinfo = pathinfo($file);
        if ($pathinfo['extension'] == 'php') {
            $models[] = 'BaseModel_' . $pathinfo['filename'];
        }
    }
}
$tables = array();
$result = Typeframe::Database()->execute('SHOW TABLES');
foreach ($result as $row) {
    $row = $row->getArray();
    //var_dump($row);
    $tableName = array_pop($row);
    $columns = array();
    //$rsCol = Typeframe::Database()->prepare('SHOW COLUMNS IN `' . $tableName . '`');
    //$rsCol->execute();
    $cols = Typeframe::Database()->execute('SHOW COLUMNS IN `' . $tableName . '`');
    //while ($col = $rsCol->fetch_array()) {
    foreach ($cols as $col) {
        $columns[] = $col['Field'];
    }
    $tables[$tableName] = $columns;
}
foreach (array_keys($tables) as $table) {
    $cls = className($table);
    if (!in_array($cls, $models)) {
        echo "The {$table} table does not have a BaseModel class.\n";
        $diffs++;
    } else {
        $mod = new $cls();
        foreach ($tables[$table] as $fld) {
            if (!$mod->field($fld)) {
Ejemplo n.º 14
0
 /**
  * Saves the userID in the session database for logging in (or out) the user.
  *
  * @param int $uid
  */
 public static function SetUID($uid)
 {
     Typeframe::Database()->prepare("UPDATE `#__sessions`\r\n      SET `uid` = ?\r\n      WHERE `sid` = ? AND `ip_addr` = ?\r\n      LIMIT 1 ;")->execute($uid, Session::$sid, REMOTE_IP);
 }