コード例 #1
0
 public function testIssetWithOverloading()
 {
     include_once "php/mt.php";
     include_once "php/lib/MTUtil.php";
     $cfg_file = realpath("t/mysql-test.cfg");
     $mt = MT::get_instance(1, $cfg_file);
     $ctx =& $mt->context();
     // Test some objects inheriting ObjectBase class.
     require_once "php/lib/class.mt_config.php";
     $config = new Config();
     $config->Load();
     $this->assertTrue(isset($config->id));
     require_once "php/lib/class.mt_author.php";
     $author = new Author();
     $author->Load();
     $this->assertTrue(isset($author->id));
     // protected variable call (bugid:113105)
     require_once "php/lib/class.mt_entry.php";
     $entry = new Entry();
     $entry->id = 1;
     $this->assertTrue(isset($entry->id));
     $this->assertNull($entry->_prefix);
     $this->assertFalse(isset($entry->_prefix));
     // fixed Dynamic publishing error occurred with memcached environment. bugid: 113546
     $mt->config('MemcachedServers', '127.0.0.1:11211');
     $obj_names = array('asset' => 'Asset', 'author' => 'Author', 'blog' => 'Blog', 'category' => 'Category', 'comment' => 'Comment', 'entry' => 'Entry', 'folder' => 'Folder', 'page' => 'Page', 'tbping' => 'TBPing', 'template' => 'Template', 'website' => 'Website');
     foreach ($obj_names as $table => $name) {
         require_once "php/lib/class.mt_{$table}.php";
         $obj = new $name();
         $obj->Load();
         $this->cache("{$table}:" . $obj->id, $obj);
         $obj_cache = $this->load_cache("{$table}:" . $obj->id);
         $this->assertInstanceOf("{$name}", $obj_cache);
     }
 }
コード例 #2
0
 private function generateRss()
 {
     $author = new Author();
     $author->clause('author_id', Application::param('author_id'));
     $posts = $author->also('Entry');
     $posts->order('entry_timestamp');
     $posts->descending();
     $posts->limit(10);
     $blog_entries = $posts->fetch();
     echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
     echo '<rss version="2.0">' . "\n";
     echo '    <channel>' . "\n";
     echo '        <title>' . $this->title() . '</title>' . "\n";
     echo '        <description>' . $this->description() . '</description>' . "\n";
     echo '        <link>' . $this->url() . '</link>' . "\n";
     foreach ($blog_entries as $entry) {
         echo '        <item>' . "\n";
         echo '            <title>' . $entry->get('entry_title') . '</title>' . "\n";
         echo '            <description>' . $entry->get('entry_body') . '</description>' . "\n";
         echo "            <link>'.{$this->url}().'/index.php?h=ViewBlogEntry</link>\n";
         echo '            <guid isPermalink="true">' . $this->url() . '/index.php?h=ViewBlogEntry&author_id=' . $entry->get('author_id') . '&entry_id=' . $entry->get('entry_id') . '</guid>' . "\n";
         echo '            <pubDate>' . $entry->entryDate() . '</pubDate>' . "\n";
         echo '        </item>' . "\n";
     }
     echo '    </channel>' . "\n";
     echo '</rss>' . "\n";
 }
コード例 #3
0
 /**
  * Helper to create "Author" model for tests.
  *
  * @param $name
  * @return Author
  */
 protected function makeAuthor($name)
 {
     $author = new Author();
     $author->name = $name;
     $author->save();
     return $author;
 }
コード例 #4
0
ファイル: BookModel.php プロジェクト: Gecata-/PHP
 public function insertBook($bookName, $bookAuthor)
 {
     $stmt = mysqli_prepare($this->connection, 'INSERT INTO books(book_title) VALUES (?)');
     mysqli_stmt_bind_param($stmt, 's', $bookName);
     mysqli_stmt_execute($stmt);
     $authorId = [];
     $author = new Author();
     $allAuthors = $author->selectAllAuthors();
     foreach ($bookAuthor as $au) {
         foreach ($allAuthors as $key => $value) {
             if ($au == $value) {
                 $authorId[] = $key;
             }
         }
     }
     $books = $this->getBook();
     $keyID = 0;
     foreach ($books as $key => $title) {
         if ($title == $bookName) {
             $keyID = $key;
         }
     }
     $stmt2 = mysqli_prepare($this->connection, 'INSERT INTO books_authors(book_id,author_id) VALUES (?,?)');
     for ($i = 0; $i < count($authorId); $i++) {
         mysqli_stmt_bind_param($stmt2, 'ii', $keyID, $authorId[$i]);
         mysqli_stmt_execute($stmt2);
     }
 }
コード例 #5
0
ファイル: OMBuilderTest.php プロジェクト: ketheriel/ETVA
    public function testToStringUsesDefaultStringFormat()
    {
        $author = new Author();
        $author->setFirstName('John');
        $author->setLastName('Doe');
        $expected = <<<EOF
Id: null
FirstName: John
LastName: Doe
Email: null
Age: null

EOF;
        $this->assertEquals($expected, (string) $author, 'generated __toString() uses default string format and exportTo()');
        $publisher = new Publisher();
        $publisher->setId(345345);
        $publisher->setName('Peguinoo');
        $expected = <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<data>
  <Id>345345</Id>
  <Name><![CDATA[Peguinoo]]></Name>
</data>

EOF;
        $this->assertEquals($expected, (string) $publisher, 'generated __toString() uses default string format and exportTo()');
    }
コード例 #6
0
 function authorInsertion($firstName, $lastName)
 {
     $author = new \Author();
     $author->setFirstName($firstName);
     $author->setLastName($lastName);
     $author->save();
     return $author;
 }
コード例 #7
0
ファイル: Test.php プロジェクト: xama5/uver-erp
 public function lol()
 {
     $author = new Author();
     $author->setFirstName('Jane' . rand(1, 100));
     $author->setLastName('Austen' . rand(1, 100));
     $author->save();
     return $author;
 }
コード例 #8
0
 function runAuthorInsertion($i)
 {
     $author = new Author();
     $author->first_name = 'John' . $i;
     $author->last_name = 'Doe' . $i;
     $author->save($this->con);
     $this->authors[] = $author->id;
 }
コード例 #9
0
 /**
  * Post name and email
  *
  * @param string $_name
  * @param string $_email
  *
  * return array {@type Author}
  *
  */
 public function post($_name, $_email)
 {
     $auth = new Author();
     $auth->name = $_name;
     $auth->email = $_email;
     $auth->save();
     return $auth;
 }
コード例 #10
0
 function runAuthorInsertion($i)
 {
     $author = new Author();
     $author->setFirstName('John' . $i);
     $author->setLastName('Doe' . $i);
     $author->save($this->con);
     $this->authors[] = $author->getId();
 }
コード例 #11
0
ファイル: 574TestCase.php プロジェクト: swk/bluebox
 /**
  * prepareData
  */
 public function prepareData()
 {
     for ($i = 0; $i < 10; $i++) {
         $oAuthor = new Author();
         $oAuthor->book_id = $i;
         $oAuthor->name = "Author {$i}";
         $oAuthor->save();
     }
 }
コード例 #12
0
 /** <tt>update test</tt> */
 public function testUpdate()
 {
     $item = new Author();
     $item->name = 'Andrei Cristescu';
     $this->assertEqual($item->insert(), $item->id);
     $item->email = '*****@*****.**';
     $this->assertEqual($item->update(), 1);
     $this->assertEqual($item->delete(), 1);
 }
コード例 #13
0
 public function testInvalidCharset()
 {
     $this->markTestSkipped();
     $db = Propel::getDB(BookPeer::DATABASE_NAME);
     if ($db instanceof DBSQLite) {
         $this->markTestSkipped();
     }
     $a = new Author();
     $a->setFirstName("Б.");
     $a->setLastName("АКУНИН");
     $a->save();
     $authorNameWindows1251 = iconv("utf-8", "windows-1251", $a->getLastName());
     $a->setLastName($authorNameWindows1251);
     // Different databases seem to handle invalid data differently (no surprise, I guess...)
     if ($db instanceof DBPostgres) {
         try {
             $a->save();
             $this->fail("Expected an exception when saving non-UTF8 data to database.");
         } catch (Exception $x) {
             print $x;
         }
     } else {
         // No exception is thrown by MySQL ... (others need to be tested still)
         $a->save();
         $a->reload();
         $this->assertEquals("", $a->getLastName(), "Expected last_name to be empty (after inserting invalid charset data)");
     }
 }
コード例 #14
0
ファイル: AuthorTest.php プロジェクト: Camolot/library
 function testSetname()
 {
     //Arrange
     $name = "Mary Shelly";
     $test_author = new Author($name);
     //Act
     $test_author->setName("Dean Koontz");
     $result = $test_author->getName();
     //Assert
     $this->assertEquals("Dean Koontz", $result);
 }
コード例 #15
0
ファイル: Book.php プロジェクト: bdspen/library_day1
 function checkAuthor($author_name)
 {
     $new_author = null;
     if (Author::findByName($author_name)) {
         $new_author = Author::findByName($author_name);
     } else {
         $new_author = new Author($author_name);
         $new_author->save();
     }
     return $new_author;
 }
コード例 #16
0
    public function testResourcesFreeSimple()
    {
        echo "Free Simple (BEFORE):" . (memory_get_usage() / 1024) . "<br/>";

        for ($i = 0; $i < 5000; $i++) {
            $author = new Author();
            $author->name = 'bar';
            $author->free(false);
        }

        echo "Free Simple (AFTER):" . (memory_get_usage() / 1024) . "<br/>";
    }
コード例 #17
0
 public static function fetchByUsername($username)
 {
     $rec = Symphony::Database()->fetchRow(0, "SELECT * FROM `tbl_authors` WHERE `username` = '{$username}' LIMIT 1");
     if (!is_array($rec) || empty($rec)) {
         return NULL;
     }
     $author = new Author();
     foreach ($rec as $field => $val) {
         $author->set($field, $val);
     }
     return $author;
 }
コード例 #18
0
 public function registerAction()
 {
     if ($this->request->isPost()) {
         $author = new Author();
         $data = $this->request->getPost('data');
         if (is_array($data) && count($data) > 0) {
             $data['password'] = password_hash($data['password'], PASSWORD_BCRYPT);
             $author->save($data);
             return $this->response->redirect('index/login');
         }
     }
 }
コード例 #19
0
ファイル: class.mt_comment.php プロジェクト: OCMO/movabletype
 public function commenter()
 {
     $commenter_id = $this->comment_commenter_id;
     if (empty($commenter_id) || !is_numeric($commenter_id)) {
         return;
     }
     require_once 'class.mt_author.php';
     $author = new Author();
     if ($author->Load("author_id = {$commenter_id}")) {
         return $author;
     }
     return null;
 }
コード例 #20
0
 /**
  * Filter the query by a related \Author object.
  * 
  * @param \Author|ObjectCollection $author The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  * @return $this|BookQuery The current query, for fluid interface
  */
 public function filterByAuthor($author, $comparison = null)
 {
     if ($author instanceof \Author) {
         return $this->addUsingAlias(BookEntityMap::COL_AUTHORID, $author->getid(), $comparison);
     } elseif ($author instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(BookEntityMap::COL_AUTHORID, $author->toKeyValue('PrimaryKey', 'id'), $comparison);
     } else {
         throw new PropelException('filterByAuthor() only accepts arguments of type \\Author or Collection');
     }
 }
コード例 #21
0
 function runAuthorInsertion($i)
 {
     $author = new Author();
     $author->setFirstName('John' . $i);
     $author->setLastName('Doe' . $i);
     $this->session->persist($author);
     $this->authors[] = $author;
     $this->i++;
     if ($this->i >= 500) {
         $this->commit();
         $this->beginTransaction();
     }
 }
コード例 #22
0
        protected function editAboutMe()
        {
            $form = Form::load('logbook.views.EditBlogAuthorDetails');

            if($form->validate())
            {
                $item = new Author();
                $item->clause('user_id',Application::current()->user()->id());
                $item->parse();
                $item->synch();
                Application::setParam('author_id',$item->id());
                $this->redirectOnSave();
            }
        }
コード例 #23
0
ファイル: BibLink.php プロジェクト: arkuuu/publin
 /**
  * Returns the link for given author and given service.
  *
  * @param Author $author  The author
  * @param string $service The service
  *
  * @return string
  */
 public static function getAuthorsLink(Author $author, $service)
 {
     switch ($service) {
         case 'Google Scholar':
             return 'http://scholar.google.com/scholar?q=' . urlencode($author->getFirstName() . ' ' . $author->getLastName());
             break;
         case 'BASE':
             return 'http://www.base-search.net/Search/Results?lookfor=aut:' . urlencode($author->getFirstName() . ' ' . $author->getLastName());
             break;
         default:
             return 'unknown service!';
             break;
     }
 }
コード例 #24
0
ファイル: classes.php プロジェクト: greenanu/phpsimpl
 /**
  * Display Form
  * 
  * @param $display array
  * @param $hidden array
  * @param $options array
  * @param $config array
  * @param $omit array
  * @return string
  */
 public function Form($display = '', $hidden = array(), $options = array(), $config = array(), $omit = array(), $multi = false)
 {
     // Get a list of all the authors
     $myAuthor = new Author();
     $authors = $myAuthor->GetList(array('first_name', 'last_name'), 'last_name', 'DESC');
     $author_list = array();
     // Format the author list how we would like
     foreach ($authors as $author_id => $author) {
         $author_list[$author_id] = $author['first_name'] . ' ' . $author['last_name'];
     }
     // Add State Options
     $this->SetOption('author_id', $author_list, 'Please Select');
     return parent::Form($display, $hidden, $options, $config, $omit, $multi);
 }
コード例 #25
0
 /** set up */
 public function setUp()
 {
     Registry::put($configurator = new MockConfigurator(), '__configurator');
     Registry::put(new Logger($configurator), '__logger');
     ActiveRecord::close_connection();
     $author = new Author();
     $author->name = 'Andrei Cristescu';
     $author->email = '*****@*****.**';
     $id = $author->save();
     $book = new Book();
     $book->author_id = $id;
     $book->title = 'The End is NEAR!';
     $book->save();
 }
コード例 #26
0
function smarty_function_mtassetaddedby($args, &$ctx)
{
    $asset = $ctx->stash('asset');
    if (!$asset) {
        return '';
    }
    require_once 'class.mt_author.php';
    $author = new Author();
    $author->Load("author_id = " . $asset->created_by);
    if ($author->nickname != '') {
        return $author->nickname;
    }
    return $author->name;
}
コード例 #27
0
    public function save()
    {
        $form = Form::load('logbook.views.AddBlogEntry');

        if($form->validate())
        {
            $auth = new Author();
            $auth->clause('user_id',Application::current()->user()->id());

            if($auth->id())
            {
                $item = new Entry();
                $item->parse();
                $item->set('author_id',$auth->id());

                if(!Application::param('entry_date'))
                    $item->set('entry_date',date('Y-m-d H:i:s'));

                $item->synch();
                Entry::setTagsAndSave($item,Application::param('entry_tags'));
                $group = new Group();
                $group->noForeign();
                $author_id = $item->get('author_id');
                $entry_id = $item->get('entry_id');
                
                if($groups = $group->fetch())
                {
                    foreach($groups as $group)
                    {
                        if(file_exists(Application::MANAGED_CODE.'lbk_default_access_'.$group->get('access_id')))
                        {
                            $data = file_get_contents(Application::MANAGED_CODE.'lbk_default_access_'.$group->get('access_id'));
                            $perms = unserialize($data);
                            ManageGroupAccess::setPermissionsOnEntryForGroup($author_id,$entry_id,$group->id(),$perms);
                        }
                    }
                }

                Application::setUrlParam('author_id',Application::param('author_id'));
                Application::setUrlParam('entry_id',Application::param('entry_id'));
                LogbookAccess::publishLookupTables();
                $this->redirectOnSave();
            }
            
            else
                die('You are not an author!');
        }
    }
コード例 #28
0
 public function loadModel($id)
 {
     if (($model = Author::model()->findByPk($id)) === null) {
         throw new CHttpException(404, 'Страница не найдена');
     }
     return $model;
 }
コード例 #29
0
 /**
  * This function determines whether an there is a currently logged in
  * Author for Symphony by using the `$Cookie`'s username
  * and password. If an Author is found, they will be logged in, otherwise
  * the `$Cookie` will be destroyed.
  *
  * @see core.Cookie#expire()
  */
 public function isLoggedIn()
 {
     // Ensures that we're in the real world.. Also reduces three queries from database
     // We must return true otherwise exceptions are not shown
     if (is_null(self::$_instance)) {
         return true;
     }
     if ($this->Author) {
         return true;
     } else {
         $username = self::Database()->cleanValue($this->Cookie->get('username'));
         $password = self::Database()->cleanValue($this->Cookie->get('pass'));
         if (strlen(trim($username)) > 0 && strlen(trim($password)) > 0) {
             $author = AuthorManager::fetch('id', 'ASC', 1, null, sprintf("\n\t\t\t\t\t\t\t`username` = '%s'\n\t\t\t\t\t\t", $username));
             if (!empty($author) && Cryptography::compare($password, current($author)->get('password'), true)) {
                 $this->Author = current($author);
                 self::Database()->update(array('last_seen' => DateTimeObj::get('Y-m-d H:i:s')), 'tbl_authors', sprintf(" `id` = %d", $this->Author->get('id')));
                 // Only set custom author language in the backend
                 if (class_exists('Administration')) {
                     Lang::set($this->Author->get('language'));
                 }
                 return true;
             }
         }
         $this->Cookie->expire();
         return false;
     }
 }
コード例 #30
0
 /**
  * Attempts to log an Author in given a username and password.
  * If the password is not hashed, it will be hashed using the sha1
  * algorithm. The username and password will be sanitized before
  * being used to query the Database. If an Author is found, they
  * will be logged in and the sanitized username and password (also hashed)
  * will be saved as values in the `$Cookie`.
  *
  * @see toolkit.Cryptography#hash()
  * @throws DatabaseException
  * @param string $username
  *  The Author's username. This will be sanitized before use.
  * @param string $password
  *  The Author's password. This will be sanitized and then hashed before use
  * @param boolean $isHash
  *  If the password provided is already hashed, setting this parameter to
  *  true will stop it becoming rehashed. By default it is false.
  * @return boolean
  *  True if the Author was logged in, false otherwise
  */
 public static function login($username, $password, $isHash = false)
 {
     $username = trim(self::Database()->cleanValue($username));
     $password = trim(self::Database()->cleanValue($password));
     if (strlen($username) > 0 && strlen($password) > 0) {
         $author = AuthorManager::fetch('id', 'ASC', 1, null, sprintf("`username` = '%s'", $username));
         if (!empty($author) && Cryptography::compare($password, current($author)->get('password'), $isHash)) {
             self::$Author = current($author);
             // Only migrate hashes if there is no update available as the update might change the tbl_authors table.
             if (self::isUpgradeAvailable() === false && Cryptography::requiresMigration(self::$Author->get('password'))) {
                 self::$Author->set('password', Cryptography::hash($password));
                 self::Database()->update(array('password' => self::$Author->get('password')), 'tbl_authors', sprintf(" `id` = %d", self::$Author->get('id')));
             }
             self::$Cookie->set('username', $username);
             self::$Cookie->set('pass', self::$Author->get('password'));
             self::Database()->update(array('last_seen' => DateTimeObj::get('Y-m-d H:i:s')), 'tbl_authors', sprintf(" `id` = %d", self::$Author->get('id')));
             // Only set custom author language in the backend
             if (class_exists('Administration', false)) {
                 Lang::set(self::$Author->get('language'));
             }
             return true;
         }
     }
     return false;
 }