Esempio n. 1
0
 public function executeVerify()
 {
     $this->redirectIf($this->getUser()->isAuthenticated(), 'ucp/index');
     $file = $this->getRequestParameter('file');
     $c = new Criteria();
     $c->add(BlogPeer::FILE, $file);
     $blog = BlogPeer::doSelectOne($c);
     if ($blog && !$blog->getVerified()) {
         $blog_url = $blog->getUrl();
         if ($blog_url[strlen($blog_url) - 1] != '/') {
             $blog_url .= '/';
         }
         $url = $blog_url . $file . '.html';
         $test1 = @fopen($url, 'r') !== false;
         $test2 = false;
         if (!$test1) {
             $contents = file_get_contents($blog_url);
             $test2 = preg_match('/<meta name="verify-phppl" content="' . $file . '" \\/>/im', $contents);
         }
         if ($test1 || $test2) {
             $blog->setVerified(true);
             $blog->save();
             $this->setFlash('verified', true);
             $this->redirect('ucp/index');
         } else {
             $this->url = $url;
             $this->file = $file;
             return sfView::ERROR;
         }
     } else {
         $this->redirect('@homepage');
     }
 }
Esempio n. 2
0
 public function executeApproved()
 {
     $this->blog = BlogPeer::retrieveByPK($this->getRequestParameter('id'));
     $this->mail = new sfMail();
     $this->mail->addAddress($this->blog->getEmail());
     $this->mail->setFrom('Planeta PHP.pl <*****@*****.**>');
     $this->mail->setSubject('Zatwierdzenie bloga');
     $this->mail->setPriority(1);
 }
 public function execute(&$value, &$error)
 {
     $mid = $this->getContext()->getRequest()->getParameter('mid');
     $c = new Criteria();
     $c->add(BlogPeer::MID, $mid);
     $blog = BlogPeer::doSelectOne($c);
     if ($blog) {
         $error = $this->getParameter('msg');
         return false;
     }
     return true;
 }
Esempio n. 4
0
 public function execute(&$value, &$error)
 {
     $login = $value;
     $password = $this->getContext()->getRequest()->getParameter($this->getParameter('password'));
     $api = new LoginAPI(sfConfig::get('app_loginapi_login'), sfConfig::get('app_loginapi_key'), $login, $password);
     switch ($api->getCode()) {
         case LoginAPI::OK:
             $mid = $api->getId();
             break;
         case LoginAPI::NON_EXISTENT:
             $error = $this->getParameter('login_error');
             break;
         case LoginAPI::INACTIVE:
             $error = $this->getParameter('inactive_error');
             break;
         case LoginAPI::INCORRECT_PASSWORD:
             $error = $this->getParameter('password_error');
             break;
         default:
             $error = $this->getParameter('unknown_error');
     }
     if (empty($error)) {
         $c = new Criteria();
         $c->add(BlogPeer::MID, $mid);
         $blog = BlogPeer::doSelectOne($c);
         if ($blog) {
             if ($blog->getVerified()) {
                 $this->getContext()->getUser()->login($blog);
                 return true;
             } else {
                 $error = $this->getParameter('not_verified_error');
             }
         } else {
             $error = $this->getParameter('no_blog_error');
         }
     }
     return false;
 }
Esempio n. 5
0
 public function executeStats()
 {
     $stats = array();
     $c = new Criteria();
     // readers_cnt
     $date = date('Y-m-d', strtotime('-1 day'));
     $c->clear();
     $c->add(ReaderPeer::DATE, $date);
     $readers = ReaderPeer::doSelectOne($c);
     $cnt = $readers ? $readers->getCnt() : 0;
     $tcnt = $cnt % 100;
     $str = '';
     if ($tcnt == 1) {
         $str = 'osoba';
     } else {
         if ($tcnt >= 12 && $tcnt <= 14) {
             $str = 'osób';
         } else {
             if ($tcnt % 10 > 1 && $tcnt % 10 < 5) {
                 $str = 'osoby';
             } else {
                 $str = 'osób';
             }
         }
     }
     $stats['reader_cnt'] = $cnt == 0 ? 'brak danych' : sprintf('%d %s', $cnt, $str);
     // blog_cnt
     $c->clear();
     $c->add(BlogPeer::APPROVED, true);
     $stats['blog_cnt'] = BlogPeer::doCount($c);
     // post_cnt
     $c->clear();
     $c->add(PostPeer::DELETED, false);
     $stats['post_cnt'] = PostPeer::doCount($c);
     // month_avg
     $c->clear();
     $c->addAscendingOrderByColumn(PostPeer::CREATED_AT);
     $post = PostPeer::doSelectOne($c);
     $ots = $post ? $post->getCreatedAt(null) : time();
     $years = date('Y') - date('Y', $ots);
     $months = $years * 12 + (date('n') - date('n', $ots));
     $stats['month_avg'] = $months > 0 ? round($stats['post_cnt'] / $months) : 0;
     // assign
     $this->stats = $stats;
 }
Esempio n. 6
0
<?php

set_time_limit(0);
define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/..'));
define('SF_APP', 'backend');
define('SF_ENVIRONMENT', 'prod');
define('SF_DEBUG', false);
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
$databaseManager = new sfDatabaseManager();
$databaseManager->initialize();
$c = new Criteria();
$c->add(BlogPeer::VERIFIED, true);
$c->add(BlogPeer::APPROVED, false);
$blogs = BlogPeer::doSelect($c);
if (empty($blogs)) {
    return;
}
$mail = new sfMail();
$mail->initialize();
$mail->setMailer('sendmail');
$mail->setCharset('utf-8');
$mail->setSubject('Lista blogów do zatwierdzenia');
$mail->setSender('*****@*****.**', 'Planeta PHP.pl');
$mail->setFrom('*****@*****.**', 'Planeta PHP.pl');
$admins = AdminPeer::doSelect(new Criteria());
foreach ($admins as $admin) {
    $mail->addAddress($admin->getEmail());
}
$body = "Oto lista blogów, które pozostały do zawierdzenia:\n";
foreach ($blogs as $blog) {
    $body .= " - {$blog->getName()} ({$blog->getUrl()})\n";
Esempio n. 7
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME,
  * TYPE_NUM. The default key type is the column's phpname (e.g. 'authorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = BlogPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setMid($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setName($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setUrl($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setFeed($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setAuthor($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setEmail($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setFile($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setVerified($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setApproved($arr[$keys[9]]);
     }
 }
Esempio n. 8
0
<?php

set_time_limit(0);
define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/..'));
define('SF_APP', 'backend');
define('SF_ENVIRONMENT', 'prod');
define('SF_DEBUG', false);
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
$databaseManager = new sfDatabaseManager();
$databaseManager->initialize();
$blogs = BlogPeer::getApproved();
logmsg('Skrypt odswiezajacy');
logmsg('Feedow do sprawdzenia: %d', count($blogs));
logmsg(str_repeat('-', 80));
foreach ($blogs as $blog) {
    logmsg('Parsowanie feedu %s', $blog->getFeed());
    try {
        $items = FeedParser::parse($blog->getFeed());
        $ts = PostPeer::getNewestTimestamp($blog);
        logmsg('Najnowszy wpis (timestamp): %d', $ts);
        foreach ($items as $item) {
            if (!parseItem($blog, $item, $ts)) {
                break;
            }
        }
    } catch (Exception $e) {
        logmsg('Blad: %s', $e->getMessage());
    }
    logmsg(str_repeat('-', 80) . "\n");
}
logmsg('Odswiezanie zakonczone.');
Esempio n. 9
0
 /**
  * Selects a collection of Post objects pre-filled with all related objects.
  *
  * @return     array Array of Post objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAll(Criteria $c, $con = null)
 {
     $c = clone $c;
     // Set the correct dbName if it has not been overridden
     if ($c->getDbName() == Propel::getDefaultDB()) {
         $c->setDbName(self::DATABASE_NAME);
     }
     PostPeer::addSelectColumns($c);
     $startcol2 = PostPeer::NUM_COLUMNS - PostPeer::NUM_LAZY_LOAD_COLUMNS + 1;
     BlogPeer::addSelectColumns($c);
     $startcol3 = $startcol2 + BlogPeer::NUM_COLUMNS;
     $c->addJoin(PostPeer::BLOG_ID, BlogPeer::ID);
     $rs = BasePeer::doSelect($c, $con);
     $results = array();
     while ($rs->next()) {
         $omClass = PostPeer::getOMClass();
         $cls = Propel::import($omClass);
         $obj1 = new $cls();
         $obj1->hydrate($rs);
         // Add objects for joined Blog rows
         $omClass = BlogPeer::getOMClass();
         $cls = Propel::import($omClass);
         $obj2 = new $cls();
         $obj2->hydrate($rs, $startcol2);
         $newObject = true;
         for ($j = 0, $resCount = count($results); $j < $resCount; $j++) {
             $temp_obj1 = $results[$j];
             $temp_obj2 = $temp_obj1->getBlog();
             // CHECKME
             if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
                 $newObject = false;
                 $temp_obj2->addPost($obj1);
                 // CHECKME
                 break;
             }
         }
         if ($newObject) {
             $obj2->initPosts();
             $obj2->addPost($obj1);
         }
         $results[] = $obj1;
     }
     return $results;
 }
Esempio n. 10
0
 public function handleErrorReject()
 {
     $this->blog = BlogPeer::retrieveByPK($this->getRequestParameter('id'));
     $this->forward404Unless($this->blog);
     return sfView::SUCCESS;
 }
Esempio n. 11
0
 /**
  * Get the associated Blog object
  *
  * @param      Connection Optional Connection object.
  * @return     Blog The associated Blog object.
  * @throws     PropelException
  */
 public function getBlog($con = null)
 {
     // include the related Peer class
     include_once 'lib/model/om/BaseBlogPeer.php';
     if ($this->aBlog === null && $this->blog_id !== null) {
         $this->aBlog = BlogPeer::retrieveByPK($this->blog_id, $con);
         /* The following can be used instead of the line above to
         		   guarantee the related object contains a reference
         		   to this object, but this level of coupling
         		   may be undesirable in many circumstances.
         		   As it can lead to a db query with many results that may
         		   never be used.
         		   $obj = BlogPeer::retrieveByPK($this->blog_id, $con);
         		   $obj->addBlogs($this);
         		 */
     }
     return $this->aBlog;
 }
Esempio n. 12
0
 protected static function doOnDeleteCascade(Criteria $criteria, Connection $con)
 {
     $affectedRows = 0;
     $objects = AuthorPeer::doSelect($criteria, $con);
     foreach ($objects as $obj) {
         include_once 'lib/model/Post.php';
         $c = new Criteria();
         $c->add(PostPeer::AUTHOR_ID, $obj->getId());
         $affectedRows += PostPeer::doDelete($c, $con);
         include_once 'lib/model/Blog.php';
         $c = new Criteria();
         $c->add(BlogPeer::AUTHOR_ID, $obj->getId());
         $affectedRows += BlogPeer::doDelete($c, $con);
     }
     return $affectedRows;
 }
Esempio n. 13
0
 public function getBlog()
 {
     return BlogPeer::retrieveByPk($this->getId());
 }
Esempio n. 14
0
 /**
  * Find object by primary key
  * Use instance pooling to avoid a database query if the object exists
  * <code>
  * $obj  = $c->findPk(12, $con);
  * </code>
  * @param     mixed $key Primary key to use for the query
  * @param     PropelPDO $con an optional connection object
  *
  * @return    Blog|array|mixed the result, formatted by the current formatter
  */
 public function findPk($key, $con = null)
 {
     if (null !== ($obj = BlogPeer::getInstanceFromPool((string) $key)) && $this->getFormatter()->isObjectFormatter()) {
         // the object is alredy in the instance pool
         return $obj;
     } else {
         // the object has not been requested yet, or the formatter is not an object formatter
         $criteria = $this->isKeepQuery() ? clone $this : $this;
         $stmt = $criteria->filterByPrimaryKey($key)->getSelectStatement($con);
         return $criteria->getFormatter()->init($criteria)->formatOne($stmt);
     }
 }
Esempio n. 15
0
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(BlogPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(BlogPeer::DATABASE_NAME);
         $criteria->add(BlogPeer::BLOG_ID, $pks, Criteria::IN);
         $objs = BlogPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Esempio n. 16
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = BlogPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setBlogId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setBlogName($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setBlogSubtitle($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setDateCreation($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setVisibility($arr[$keys[4]]);
     }
 }
Esempio n. 17
0
 public function countBlogs($criteria = null, $distinct = false, $con = null)
 {
     include_once 'lib/model/om/BaseBlogPeer.php';
     if ($criteria === null) {
         $criteria = new Criteria();
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     $criteria->add(BlogPeer::AUTHOR_ID, $this->getId());
     return BlogPeer::doCount($criteria, $distinct, $con);
 }