Ejemplo n.º 1
0
 protected function attachImage(Entity $entity, $url, $title = '', $caption = '', $is_featured = 1, $is_free = 0)
 {
     if (preg_match('/^https/', $url)) {
         $this->printDebug("HTTPS protocol");
         return false;
     }
     try {
         $filename = ImageTable::createFiles($url, basename($url));
     } catch (Exception $e) {
         $this->printDebug($e);
         return false;
     }
     if (!$filename) {
         $this->printDebug("File could not be created");
         return false;
     }
     $this->printDebug("Creating file: " . $filename);
     //insert image row
     $image = new Image();
     $image->Entity = $entity;
     $image->filename = $filename;
     $image->url = $url;
     $image->title = $title;
     $image->caption = $caption;
     $image->is_featured = $is_featured;
     $image->is_free = $is_free;
     $image->save();
     $image->addReference($url, null, array('filename'));
     $this->printDebug("Imported image with ID: " . $image->getId());
     return true;
 }
Ejemplo n.º 2
0
 function uploadFile($type, $filename, $check_first = true, $debug = false)
 {
     $localPath = sfConfig::get('sf_image_dir') . DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR . $filename;
     $input = $this->s3->inputResource($f = fopen($localPath, "rb"), filesize($s = $localPath));
     $uri = ImageTable::generateS3path($type, $filename);
     if ($check_first && $this->s3->getObjectInfo(sfConfig::get('app_amazon_s3_bucket'), $uri) !== false) {
         return;
     }
     if (S3::putObject($input, sfConfig::get('app_amazon_s3_bucket'), $uri, S3::ACL_PUBLIC_READ)) {
         print "UPLOADED: " . $uri . "\n";
     } else {
         if ($debug) {
             print "Couldn't upload image to S3: " . $uri . "\n";
         }
     }
 }
Ejemplo n.º 3
0
 public static function prepareEntityData($entity)
 {
     sfLoader::loadHelpers(array("Asset", "Url"));
     $primary_ext = @$entity["primary_ext"] ? $entity["primary_ext"] : (strpos($entity["url"], "person") === false ? "Org" : "Person");
     $entity["primary_ext"] = $primary_ext;
     if (@$entity["image"] && strpos(@$entity["image"], "netmap") === false && strpos(@$entity["image"], "anon") === false) {
         $image_path = $entity["image"];
     } elseif (@$entity["filename"]) {
         $image_path = image_path(ImageTable::getPath($entity['filename'], 'profile'));
     } else {
         $image_path = $primary_ext == "Person" ? image_path("system/netmap-person.png") : image_path("system/netmap-org.png");
     }
     try {
         $url = url_for(EntityTable::generateRoute($entity));
     } catch (Exception $e) {
         $url = 'http://littlesis.org/' . strtolower($primary_ext) . '/' . $entity['id'] . '/' . LsSlug::convertNameToSlug($entity['name']);
     }
     if (@$entity["blurb"]) {
         $description = $entity["blurb"];
     } else {
         $description = @$entity["description"];
     }
     return array("id" => self::integerize(@$entity["id"]), "name" => $entity["name"], "image" => $image_path, "url" => $url, "description" => $description, "x" => @$entity["x"], "y" => @$entity["y"], "fixed" => true);
 }
Ejemplo n.º 4
0
/**
 * Returns the path to an image asset.
 *
 * <b>Example:</b>
 * <code>
 *  echo image_path('foobar');
 *    => /images/foobar.png
 * </code>
 *
 * <b>Note:</b> The asset name can be supplied as a...
 * - full path, like "/my_images/image.gif"
 * - file name, like "rss.gif", that gets expanded to "/images/rss.gif"
 * - file name without extension, like "logo", that gets expanded to "/images/logo.png"
 * 
 * @param  string $source    asset name
 * @param  bool   $absolute  return absolute path ?
 *
 * @return string file path to the image file
 * @see    image_tag  
 */
function image_path($source, $absolute = false, $override = false)
{
    // CHANGE TO SYMFONY'S ASSETHELPER
    if (!$override && sfConfig::get('app_amazon_enable_s3')) {
        $source = ImageTable::generateS3Url($source);
    }
    return _compute_public_path($source, 'images', 'png', $absolute);
}
Ejemplo n.º 5
0
 static function getImages($id, $options = array())
 {
     $db = Doctrine_Manager::connection();
     // include images belonging to individuals that part of couples on the list
     $entityIds = self::getEntityIds($id, array('expand_couples' => $options['expand_couples']));
     if (count($entityIds) > 0) {
         if (isset($options['with_address']) && $options['with_address'] == '1') {
             $sql = 'SELECT i.entity_id, i.id AS image_id, i.filename FROM image i WHERE i.entity_id IN(' . join(',', $entityIds) . ') AND i.is_deleted = 0 AND i.address_id IS NOT NULL';
         } else {
             if (isset($options['all_images']) && $options['all_images'] == '1') {
                 $sql = 'SELECT i.entity_id, i.id AS image_id, i.filename FROM image i WHERE i.entity_id IN(' . join(',', $entityIds) . ') AND i.is_deleted = 0';
             } else {
                 $sql = 'SELECT i.entity_id, i.id AS image_id, i.filename FROM image i WHERE i.entity_id IN(' . join(',', $entityIds) . ') AND i.is_featured = 1 AND i.is_deleted = 0 AND i.address_id IS NULL';
             }
         }
         $stmt = $db->execute($sql, array($id));
         $rows = $stmt->fetchAll();
     } else {
         $rows = array();
     }
     return array_map(function ($row) {
         return array('id' => intval($row['entity_id']), 'url' => ImageTable::generateS3Url('profile/' . $row['filename']), 'image_id' => intval($row['image_id']));
     }, $rows);
 }
Ejemplo n.º 6
0
 public function execute()
 {
     if (!$this->safeToRun('uk-mp-candidates')) {
         $this->printDebug('Script already running');
         die;
     }
     // Get (or create) the UK local Network
     $uk = Doctrine::getTable('LsList')->findOneByName('United Kingdom');
     if (!$uk) {
         $uk = new LsList();
         $uk->name = 'United Kingdom';
         $uk->is_network = 1;
         $uk->description = 'People and organizations with significant influence on the policies of the United Kingdom';
         $uk->display_name = 'uk';
         $uk->save();
     }
     // Get the MP list
     $raw = $this->getMPs();
     // Add new MPs to the list
     foreach ($raw as $mp) {
         $this->printDebug(sprintf('Processing %s', $mp['name']));
         // Split name
         $entity = PersonTable::parseFlatName($mp['name']);
         $entity->blurb = 'Prospective Parliamentary Candidate for ' . $mp['constituency'];
         $q = TagTable::getByTripleQuery('yournextmp', 'url', $mp['url']);
         $r = $q->count();
         if ($r) {
             $this->printDebug('Already processed, skipping.');
             continue;
         }
         // Get political party
         $q = EntityTable::getByExtensionQuery('PoliticalParty')->addWhere('e.name = ?', $mp['party']);
         if (!($partyEntity = $q->fetchOne())) {
             $partyEntity = new Entity();
             $partyEntity->addExtension('Org');
             $partyEntity->addExtension('PoliticalParty');
             $partyEntity->name = $mp['party'];
             $partyEntity->blurb = 'UK Political Party';
             $partyEntity->save(null, true, array($uk->id));
             $this->printDebug("Created new political party: " . $mp['party']);
         }
         // Save entity to UK Network
         $entity->party_id = $partyEntity->id;
         $entity->save(null, true, array($uk->id));
         // Add party relationship
         $r = new Relationship();
         $r->entity1_id = $entity->id;
         $r->entity2_id = $partyEntity->id;
         $r->setCategory('Membership');
         $r->description1 = 'Prospective parliamentary candidate';
         $r->is_current = true;
         // $r->start_date = // Don't know where we can get this, and "now" seems kind of wrong
         $r->save();
         // Add YourNextMP triple
         $entity->addTagByTriple('yournextmp', 'url', $mp['url']);
         // Add references
         $ref = new Reference();
         $ref->addFields(array('name_first', 'name_last', 'name_middle'));
         // Don't need this
         $ref->source = $mp['url'];
         $ref->name = 'YourNextMP.com - ' . $entity['name'];
         $ref->object_model = 'Entity';
         $ref->object_id = $entity->getId();
         $ref->save();
         unset($ref);
         $ref = new Reference();
         $ref->addFields(array('name'));
         $ref->source = $mp['party_url'];
         $ref->name = 'YourNextMP.com - ' . $partyEntity['name'];
         $ref->object_model = 'Entity';
         $ref->object_id = $partyEntity->getId();
         $ref->save();
         unset($ref);
         $ref = new Reference();
         $ref->addFields(array('name'));
         $ref->source = $mp['url'];
         $ref->name = 'YourNextMP.com - ' . $entity['name'];
         $ref->object_model = 'Relationship';
         $ref->object_id = $r->getId();
         $ref->save();
         unset($ref);
         $r->free(true);
         unset($r);
         // Add image?
         if ($mp['image']) {
             if ($fileName = ImageTable::createFiles($mp['image'])) {
                 //insert image record
                 $image = new Image();
                 $image->filename = $fileName;
                 $image->title = $entity['name'];
                 $image->caption = 'From YourNextMP under CC-BY-SA license.';
                 $image->is_featured = true;
                 $image->is_free = true;
                 $image->url = $mp['image'];
                 $this->printDebug("Imported image: " . $image->filename);
             }
             $image->Entity = $entity;
             $image->save();
             if ($mp['image']) {
                 //save image source
                 $image->addReference($mp['image']);
                 $this->printDebug("Saved image reference");
             }
             unset($image);
         }
         // Add party image?
         if ($mp['party_image']) {
             if ($fileName = ImageTable::createFiles($mp['party_image'])) {
                 //insert image record
                 $partyImage = new Image();
                 $partyImage->filename = $fileName;
                 $partyImage->title = $partyEntity['name'];
                 $partyImage->caption = 'From YourNextMP under CC-BY-SA license.';
                 $partyImage->is_featured = true;
                 $partyImage->is_free = true;
                 $partyImage->url = $mp['party_image'];
                 $this->printDebug("Imported image: " . $partyImage->filename);
             }
             $partyImage->Entity = $partyEntity;
             $partyImage->save();
             if ($mp['party_image']) {
                 //save image source
                 $partyImage->addReference($mp['party_image']);
                 $this->printDebug("Saved image reference");
             }
             unset($partyImage);
         }
         unset($entity);
         unset($partyEntity);
     }
 }
Ejemplo n.º 7
0
<?php 
$col = -1;
?>
  <tr>
<?php 
foreach ($entities as $entity) {
    ?>
  <?php 
    if ($col == 4) {
        ?>
  </tr>
  <tr>
  <?php 
    }
    ?>
    <td style="vertical-align: top; text-align: center; padding: 0.8em; padding-bottom: 1.2em;">
      <?php 
    echo link_to(image_tag(ImageTable::getPath($entity['Image'][0]['filename'], 'profile'), array('alt' => '', 'style' => 'height: 100px; border: 0;')), EntityTable::getInternalUrl($entity));
    ?>
      <br />
      <br />
      <?php 
    echo entity_link($entity, null);
    ?>
    </td>
  <?php 
    $col = ($col + 1) % 5;
}
?>
  </tr>
</table>
 public function getProfileData($member)
 {
     //generate URL for member's profile
     $url = $this->_profileUrlBase . $member->bioguide_id;
     $this->_references['bioguide']->source = $url;
     $this->_references['bioguide']->name = 'Congressional Biographical Directory';
     if (!$this->browser->get($url)->responseIsError()) {
         $this->printDebug("Fetched member's profile page");
         $this->_bioPageText = $text = LsString::newlinesToSpaces($this->browser->getResponseText());
         //get bio
         if (preg_match('/, <\\/FONT>([^<]+)<\\/(TD|P)>/', $text, $bio)) {
             $bio = preg_replace('/\\n/', ' ', $bio[1]);
             $bio = ucfirst(trim(preg_replace('/\\s{2,}/', ' ', $bio)));
             $bio = LsHtml::replaceEntities($bio);
             $member->summary = $bio;
             $this->printDebug("Bio: " . $bio);
             if (preg_match('/\\b(a(\\s+\\p{L}+){2,8})\\;/isu', $bio, $match)) {
                 $blurb = 'US ' . preg_replace('/a\\s+/isu', '', $match[1]);
                 $member->blurb = $blurb;
                 $this->printDebug("Blurb: " . $blurb);
             }
         }
         //get senate term, if any
         if (preg_match('/Service:<\\/B><\\/FONT>([^<]+)<BR>/', $text, $term)) {
             $terms = preg_split('/,;/', $term[1]);
             foreach ($terms as $term) {
                 if (!($term = trim($term))) {
                     continue;
                 }
                 //create relationship
                 $rel = new Relationship();
                 $rel->Entity1 = $member;
                 $rel->entity2_id = $this->_senateEntityId;
                 $rel->setCategory('Membership');
                 $rel->description1 = 'Senator';
                 //break term into start and end
                 $years = explode('-', $term);
                 $start = trim($years[0]);
                 $rel->start_date = $start . '-00-00';
                 $this->printDebug("Senate term start: " . $start);
                 if (count($years) > 1 && trim($years[1])) {
                     $end = trim($years[1]);
                     $rel->end_date = $end . '-00-00';
                     $this->printDebug("Senate term end: " . $end);
                 }
                 $this->_senateRelationships[] = $rel;
                 $this->printDebug("Created relationship to US Senate");
             }
         }
         //get house terms
         preg_match_all('/\\((\\w+\\s+\\d{1,2},\\s+\\d{4})-(present|(\\w+\\s+\\d{1,2},\\s+\\d{4}))\\)/ismU', $text, $matches, PREG_SET_ORDER);
         foreach ($matches as $match) {
             if ($time = strtotime($match[1])) {
                 //create relationship
                 $rel = new Relationship();
                 $rel->Entity1 = $member;
                 $rel->entity2_id = $this->_houseEntityId;
                 $rel->setCategory('Membership');
                 $rel->start_date = date('Y-m-d', $time);
                 $rel->description1 = 'Representative';
                 $this->printDebug("Created relationship to US House of Reps");
                 $this->printDebug("House term start: " . $rel->start_date);
                 if ($match[2] != 'present' && ($time = strtotime($match[2]))) {
                     $rel->end_date = date('Y-m-d', $time);
                     $this->printDebug("House term end: " . $rel->end_date);
                 }
                 $this->_houseRelationships[] = $rel;
             }
         }
         //get photo url & name
         if (preg_match('/bioguide\\/photo\\/[A-Z]\\/([^"]+)/', $text, $photo)) {
             if ($photoUrl = $photo[0]) {
                 $this->_photoUrl = 'http://bioguide.congress.gov/' . $photoUrl;
                 $photoName = $photo[1];
                 $this->printDebug("Photo URL: " . $this->_photoUrl);
                 //get photo credit
                 if (preg_match('/<I>([^<]+)<\\/photo\\-credit>/', $text, $credit)) {
                     $credit = trim($credit[1]);
                     $this->printDebug("Photo credit: " . $credit);
                 } else {
                     $credit = null;
                 }
                 if ($fileName = ImageTable::createFiles($this->_photoUrl, $photoName)) {
                     //insert image record
                     $image = new Image();
                     $image->filename = $fileName;
                     $image->title = 'Congress Photo';
                     $image->caption = $credit ? $credit : 'From the Biographical Directory of the United States Congress';
                     $image->is_featured = true;
                     $image->is_free = true;
                     $image->url = $this->_photoUrl;
                     //save for later
                     $this->_image = $image;
                     $this->printDebug("Imported image: " . $image->filename);
                 }
             }
         }
     } else {
         //Error response (eg. 404, 500, etc)
         throw new Exception("Couldn't get " . $url);
     }
 }
Ejemplo n.º 9
0
 public function getInternalUrl()
 {
     return ImageTable::getInternalUrl($this);
 }
Ejemplo n.º 10
0
    echo link_to('search', 'http://google.com/images?q=' . urlencode($entity['name']), 'target=_blank');
    ?>
    </td>
    
    <td>
      <?php 
    echo entity_link($entity);
    ?>
    </td>
    
    <td>
      <?php 
    if ($image = $entity['Image'][0]['filename']) {
        ?>
        <?php 
        echo link_to(image_tag(ImageTable::getPath($image, 'profile'), array('alt' => '', 'style' => 'height: 80px; border: 0;')), EntityTable::getInternalUrl($entity));
        ?>
      <?php 
    }
    ?>
    </td>

    <td>
      <?php 
    echo $entity['summary'];
    ?>
    </td>
    
  </tr>
    <?php 
    $row++;
Ejemplo n.º 11
0
" style="position: absolute; top: 0; right: 0; display: none; height: 16px; width: 16px;">
    <div style="background-color: #fff;">
      <?php 
echo image_tag('system/edit-pencil.png');
?>
    </div>
  </a>
<?php 
$image = EntityTable::getProfileImageById($entity['id']);
if ($image) {
    ?>
	<?php 
    echo link_to(image_tag(ImageTable::getPath($image, 'profile'), array('alt' => '')), EntityTable::getInternalUrl($entity, 'images'));
    ?>
  <?php 
    slot('share_image', ImageTable::getPath($image, 'profile'));
} else {
    ?>
  <?php 
    $file = $entity['primary_ext'] == 'Person' ? 'anon.png' : 'anons.png';
    ?>
	<?php 
    echo link_to(image_tag('system' . DIRECTORY_SEPARATOR . $file, array('alt' => 'Upload Image')), EntityTable::getInternalUrl($entity, 'uploadImage'));
}
?>

<?php 
if ($image['caption']) {
    ?>
  <div class="image_caption"><?php 
    echo $image['caption'];
Ejemplo n.º 12
0
 private function importDirectorInfo($info, $age_match)
 {
     $id = $age_match['name_match']['id'];
     $person = $age_match['name_match']['person'];
     $this->printDebug($person->name);
     $category = Doctrine::getTable('RelationshipCategory')->findOneByName('Position');
     $relationship = LsDoctrineQuery::create()->from('Relationship r')->where('r.entity1_id = ?', $id)->addWhere('r.entity2_id = ?', $this->corp->id)->addWhere('r.category_id = ?', $category->id)->addWhere('r.description1 = ?', 'Director')->fetchOne();
     if ($info['since']) {
         $relationship->start_date = $info['since'] . '-00-00';
         $relationship->save();
         $this->printDebug('Director since: ' . $relationship->start_date);
         $relationship->addReference($this->url, null, array('start_date'), $this->corp->name . ' ' . $this->year . ' Proxy', 'pg ' . $age_match['name_match']['page_number']);
     }
     if ($info['blurb'] != '') {
         $info['blurb'] = $this->cleanSummary($info['blurb']);
         if (strlen($info['blurb']) > 3000) {
             $info['blurb'] = substr($info['blurb'], 0, 3000);
         }
         if ($person->summary == null) {
             $person->summary = $info['blurb'];
             $person->save();
             $person->addReference($this->url, $info['blurb'], array('summary'), $this->corp->name . ' ' . $this->year . ' Proxy', 'pg ' . $age_match['name_match']['page_number']);
             $this->printDebug('Summary: ' . $person->summary);
         } else {
             $person->addReference($this->url, $info['blurb'], array('summary'), $this->corp->name . ' ' . $this->year . ' Proxy', 'pg ' . $age_match['name_match']['page_number']);
         }
     } else {
         $this->printDebug('no blurb');
     }
     if ($person->start_date == null) {
         $person->start_date = $this->year - $age_match['age'] . '-00-00';
         $person->save();
         $person->addReference($this->url, $info['blurb'], array('start_date'), $this->corp->name . ' ' . $this->year . ' Proxy', 'pg ' . $age_match['name_match']['page_number']);
         $this->printDebug('Birthdate: ' . $person->start_date);
     }
     if (isset($info['img'])) {
         $url = substr($this->url, 0, strrpos($this->url, '/') + 1) . $info['img'];
         if ($fileName = ImageTable::createFiles($url, $info['img'])) {
             //insert image record
             $image = new Image();
             $image->filename = $fileName;
             $image->entity_id = $person->id;
             $image->title = $person->name;
             $image->caption = 'From ' . $this->corp->name . '\'s proxy filing.';
             $image->is_featured = true;
             $image->is_free = false;
             $image->url = $url;
             $q = LsDoctrineQuery::create()->from('Image i')->where('i.entity_id = ?', $person->id)->addWhere('i.title =?', $person->name)->addWhere('i.caption =?', $image->caption);
             if (count($q->execute()) == 0) {
                 $image->save();
                 $image->addReference($this->url, null, array('filename'), $this->corp->name . ' ' . $this->year . ' Proxy', 'pg ' . $age_match['name_match']['page_number']);
                 $this->printDebug("Imported image: " . $image->filename);
             }
         }
     }
 }
Ejemplo n.º 13
0
 public function executeUploadImage($request)
 {
     $this->checkUser();
     $this->user = $this->getUser();
     $this->profile = $this->getUser()->getProfile();
     $this->upload_form = new ImageUploadForm();
     $params = $request->getParameter('image');
     if ($request->isMethod('post')) {
         $db = Doctrine_Manager::connection();
         //$this->upload_form->bind($params, $request->getFiles('image'));
         try {
             $db->beginTransaction();
             $files = $request->getFiles('image');
             //set filename and path based on upload type
             if (isset($files['file']['size']) && $files['file']['size']) {
                 $path = $request->getFilePath('image');
                 $path = $path['file'];
                 $originalFilename = $request->getFileName('image');
                 $originalFilename = $originalFilename['file'];
             } else {
                 $path = $params['url'];
                 $pathParts = explode('?', basename($path));
                 $originalFilename = $pathParts[0];
             }
             //if image files can't be created, assume remote url was bad
             if (!($filename = ImageTable::createFiles($path, $originalFilename))) {
                 $validatorSchema = $this->upload_form->getValidatorSchema();
                 $this->upload_form->getErrorSchema()->addError(new sfValidatorError($validatorSchema['url'], 'invalid'));
                 return sfView::SUCCESS;
             }
             $this->profile->filename = $filename;
             $this->profile->save();
             //create reference
             //if featured, unfeature any other images
             if (isset($params['featured']) && ($profileImage = $entity->getProfileImage())) {
                 $profileImage->is_featured = false;
                 $profileImage->save();
             }
             $db->commit();
         } catch (Exception $e) {
             $db->rollback();
             throw $e;
         }
         $this->clearUserCache();
         $this->redirect($request->getParameter('referer', 'home/notes'));
     }
 }
Ejemplo n.º 14
0
 protected function attachImage(Entity $entity, $url)
 {
     $filename = ImageTable::createFiles(preg_replace('/^https/i', 'http', $url), basename($url));
     if ($filename) {
         $this->printDebug("Filename saved as " . $filename);
         //insert image row
         $image = new Image();
         $image->Entity = $entity;
         $image->filename = $filename;
         $image->url = $url;
         $image->title = $entity->name;
         $image->is_featured = 1;
         $image->is_free = 0;
         $image->save();
         $image->addReference($url, null, array('filename'), 'Forbes.com');
         $this->printDebug("Imported image ID: " . $image->getId());
         return true;
     } else {
         $this->printDebug("File could not be created");
         return false;
     }
 }
Ejemplo n.º 15
0
 protected function importGovernor($row)
 {
     $url = $this->_baseUrl . $row['url'];
     if (!$this->browser->get($url)->responseIsError()) {
         $text = $this->browser->getResponseText();
         $text = LsHtml::replaceEntities($text);
         //preg_match('/>Family\:<\/b>([^<]*)<br/is',$text,$family_arr);
         $name = trim(str_ireplace('Gov.', '', $row['name']));
         $this->printDebug('');
         $this->printDebug($name . ':');
         $governor = PersonTable::parseFlatName($name);
         $governor->addExtension('PoliticalCandidate');
         $governor->addExtension('ElectedRepresentative');
         $governor->is_state = 1;
         $similar = $governor->getSimilarEntitiesQuery(true)->execute();
         foreach ($similar as $s) {
             $sim_re = LsString::escapeStringForRegex($s->name_first);
             $search_re = LsString::escapeStringForRegex($governor->name_first);
             if (preg_match('/^' . $sim_re . '/su', $governor->name_first) == 0 && preg_match('/^' . $search_re . '/su', $s->name_first) == 0) {
                 continue;
             }
             $bio = $s->getExtendedBio();
             if (preg_match('/\\bgovernor(ship)?\\b/isu', $bio)) {
                 $governor = $s;
                 $this->printDebug(' Found existing governor: ' . $s->name . ' ' . $s->id);
                 break;
             }
         }
         $governor->save();
         $this->printDebug($governor->id);
         if (!$governor->start_date && preg_match('/>Born\\:<\\/b>([^<]*)<br/is', $text, $birth_arr)) {
             $this->printDebug(' Birthdate: ' . $birth_arr[1]);
             $governor->start_date = trim($birth_arr[1]);
         }
         if (!$governor->birthplace && preg_match('/>Birth State\\:<\\/b>([^<]*)<br/is', $text, $birth_state_arr)) {
             $this->printDebug(' Birthplace: ' . trim($birth_state_arr[1]));
             $governor->birthplace = trim($birth_state_arr[1]);
         }
         //PARTY MEMBERSHIP
         if (preg_match('/>Party\\:<\\/b>([^<]*)<br/is', $text, $party_arr)) {
             $party_str = $party_arr[1];
             $this->printDebug(' Party: ' . $party_str);
             if (stristr($party_str, 'Democrat')) {
                 $party = EntityTable::getByExtensionQuery('PoliticalParty')->addWhere('name = ?', 'Democratic Party')->fetchOne();
             }
             if (stristr($party_str, 'Republican')) {
                 $party = EntityTable::getByExtensionQuery('PoliticalParty')->addWhere('name = ?', 'Republican Party')->fetchOne();
             }
             if (isset($party) && $party && !$governor->party_id) {
                 $governor->Party = $party;
                 $governor->is_independent = false;
                 $this->printDebug(' Added membership in ' . $party);
             } else {
                 if (stristr($party_str, 'Independent')) {
                     $governor->is_independent = true;
                 }
             }
         }
         if (!$governor->summary && preg_match_all('/>([^<]{240,})/isu', $text, $bio_match)) {
             $str = '';
             foreach ($bio_match[1] as $b) {
                 if (!stristr($b, 'Javascript')) {
                     $str .= "\n\n" . $b;
                 }
             }
             $str = trim($str);
             if (strlen($str)) {
                 $governor->summary = $str;
             }
         }
         $governor->save();
         $governor->addReference($url, null, $governor->getAllModifiedFields(), 'Governors Association');
         //SCHOOLS
         if (preg_match('/>School\\(s\\)\\:<\\/b>([^<]*)<br/is', $text, $school_arr)) {
             $school_names = explode(';', trim($school_arr[1]));
             if (count($school_names) == 1) {
                 $school_names = explode(',', $school_names[0]);
             }
             foreach ($school_names as $school_name) {
                 $school_name = trim($school_name);
                 if (!($school = EntityTable::getByExtensionQuery('School')->leftJoin('e.Alias a')->addWhere('e.name = ? or a.name = ?', array($school_name, $school_name))->fetchOne())) {
                     $school = new Entity();
                     $school->addExtension('Org');
                     $school->addExtension('School');
                     $school->name = $school_name;
                     $school->save();
                     $this->printDebug(' Added School: ' . $school_name);
                 }
                 $q = RelationshipTable::getByCategoryQuery('Education')->addWhere('entity1_id = ? and entity2_id = ?', array($governor->id, $school->id))->fetchOne();
                 if (!$q) {
                     $relationship = new Relationship();
                     $relationship->setCategory('Education');
                     $relationship->Entity1 = $governor;
                     $relationship->Entity2 = $school;
                     $relationship->is_current = 0;
                     $relationship->save();
                     $relationship->addReference($url, null, $relationship->getAllModifiedFields(), 'Governors Association');
                     $this->printDebug(' Added education: ' . $relationship->name);
                 }
             }
         }
         //GOVERNOR OFFICE AND POSITION
         $office_name = 'Office of the Governor of ' . $row['state'];
         if (!($office = EntityTable::getByExtensionQuery('GovernmentBody')->addWhere('name = ?', $office_name)->fetchOne())) {
             $office = new Entity();
             $office->name = $office_name;
             $office->addExtension('Org');
             $office->addExtension('GovernmentBody');
             $state = Doctrine::getTable('AddressState')->findOneByName($row['state']);
             if ($state) {
                 $office->state_id = $state->id;
             }
             $office->save();
             $office->addReference($url, null, $office->getAllModifiedFields(), 'Governors Association');
             $this->printDebug(' Added office: ' . $office->name);
         }
         $q = RelationshipTable::getByCategoryQuery('Position')->addWhere('entity1_id = ? and entity2_id = ? and description1 = ?', array($governor->id, $office->id, 'Governor'))->fetchOne();
         if (!$q) {
             sort($row['years']);
             $i = 0;
             while ($i < count($row['years'])) {
                 $governorship = new Relationship();
                 $governorship->setCategory('Position');
                 $governorship->Entity1 = $governor;
                 $governorship->Entity2 = $office;
                 $governorship->description1 = 'Governor';
                 $governorship->start_date = $row['years'][$i];
                 $i++;
                 if (isset($row['years'][$i])) {
                     $governorship->end_date = $row['years'][$i];
                     $governorship->is_current = 0;
                     if (!$governor->blurb && !isset($row['years'][$i + 1])) {
                         $governor->blurb = 'Former Governor of ' . $row['state'];
                     }
                 } else {
                     $governorship->is_current = 1;
                     if (!$governor->blurb) {
                         $governor->blurb = 'Governor of ' . $row['state'];
                     }
                 }
                 $governor->save();
                 $i++;
                 $governorship->save();
                 $governorship->addReference($url, null, $governorship->getAllModifiedFields(), 'Governors Association');
                 $this->printDebug(' Added governorship: ' . $governorship->name);
             }
         }
         //SPOUSE
         if (preg_match('/>Spouse\\:<\\/b>(.*?)<br/is', $text, $spouse_arr)) {
             $spouse = trim(LsHtml::stripTags($spouse_arr[1]));
             $q = RelationshipTable::getByCategoryQuery('Family')->addWhere('entity1_id = ? or entity2_id = ?', array($governor->id, $governor->id))->fetchOne();
             if (!$q && strlen($spouse)) {
                 $spouse = PersonTable::parseFlatName($spouse);
                 $spouse->save();
                 $this->printDebug(' Added spouse: ' . $spouse->name);
                 $relationship = new Relationship();
                 $relationship->setCategory('Family');
                 $relationship->Entity1 = $spouse;
                 $relationship->Entity2 = $governor;
                 $relationship->description1 = 'Spouse';
                 $relationship->description2 = 'Spouse';
                 $relationship->save();
                 $relationship->addReference($url, null, $relationship->getAllModifiedFields(), 'Governors Association');
                 $this->printDebug(' Added spouse relationship: ' . $relationship->name);
             }
         }
         //ADDRESS --not working, malformed addresses
         /*
               if (preg_match('/>Address\:\s*<\/b>(.*?)<b>/is',$text,$address_arr))      
               {
                 $address = trim(str_replace('<br/>',', ',$address_arr[1]));
                 $this->printDebug($address);
                 if ($governor->Address->count() == 0 && $a = $governor->addAddress($address))
                 {
                   $this->printDebug(' Address: ' . $a);
                   $governor->save();
                 }
               }*/
         //PHONE NUMBER
         if (preg_match('/>Phone\\(s\\)\\:<\\/b>([^<]*)<br/is', $text, $phone_arr)) {
             $phone_number = trim($phone_arr[1]);
             if (!$governor->Phone->count()) {
                 $phone = $governor->addPhone($phone_number);
                 $this->printDebug(' Phone: ' . $phone);
             }
         }
         if (!$governor->Image->count() && preg_match('/<img .*?class\\="display" src\\="([^"]*)"/is', $text, $img_arr)) {
             $url = $img_arr[1];
             try {
                 $fileName = ImageTable::createFiles($url, $governor->name_first);
             } catch (Exception $e) {
                 $fileName = null;
             }
             if ($fileName) {
                 //insert image record
                 $image = new Image();
                 $image->filename = $fileName;
                 $image->entity_id = $governor->id;
                 $image->title = $governor->name;
                 $image->caption = 'From Governors Association website';
                 $image->is_featured = true;
                 $image->is_free = false;
                 $image->url = $url;
                 $image->save();
                 $this->printDebug("Imported image: " . $image->filename);
             }
         }
     }
 }
Ejemplo n.º 16
0
function ls_image_tag($source, $options = array())
{
    if (sfConfig::get('app_amazon_enable_s3')) {
        $source = ImageTable::generateS3Url($source);
    }
    return image_tag($source, $options);
}
Ejemplo n.º 17
0
<?php

use_helper('LsText');
?>

<?php 
if ($entity) {
    ?>
<div class="entity-carousel">
  <div class="entity-carousel-image" style="background-image: url(<?php 
    echo image_path(ImageTable::getPath($entity['image_path'], 'square'));
    ?>
);">
  </div>

  <div class="entity-carousel-text">
    <?php 
    echo entity_link($entity, 'entity-carousel-name');
    ?>
<br />
  
    <?php 
    if ($entity['blurb']) {
        ?>
      <span class="entity-carousel-description"><?php 
        echo $entity['blurb'];
        ?>
<br /></span>
    <?php 
    }
    ?>
Ejemplo n.º 18
0
 private function getLobbyistInfo($org)
 {
     $people = $org->getRelatedEntitiesQuery('Person', RelationshipTable::POSITION_CATEGORY, null, null, null, false)->addWhere('summary is NULL or summary = ?', '')->execute();
     $google_scraper = new LsGoogle();
     $ct = 0;
     foreach ($people as $person) {
         if ($ct > 30) {
             return null;
         }
         $this->printDebug("\n******************\n");
         $bio = null;
         $image = null;
         $query = 'site:' . $org->website . ' ' . $person->name;
         $this->printDebug('Query: ' . $query);
         $google_scraper->setQuery(trim($query));
         $google_scraper->execute();
         if ($google_scraper->getNumResults()) {
             $results = $google_scraper->getResults();
             $match_sets = array();
             $this->stopTimer();
             $last = $this->timer->getElapsedTime();
             $this->beginTimer();
             foreach ($results as $result) {
                 $this->stopTimer();
                 $now = $this->timer->getElapsedTime();
                 $diff = $now - $last;
                 $this->printDebug($diff);
                 $last = $now;
                 $this->beginTimer();
                 if ($diff > 30) {
                     try {
                         $this->db->beginTransaction();
                         $this->saveMeta($org->id, 'timeout', 1);
                         $this->printDebug('TIMEOUT=======================================');
                         if (!$this->testMode) {
                             $this->db->commit();
                         } else {
                             $this->db->rollback();
                         }
                     } catch (Exception $e) {
                         $this->db->rollback();
                     }
                     return null;
                 }
                 if (0) {
                     $url = $result->cacheUrl;
                 } else {
                     $url = $result->unescapedUrl;
                 }
                 $this->printDebug($url);
                 if (preg_match('/\\.pdf$/is', $url)) {
                     $this->printDebug("PDF, skipping ({$url})\n----------------");
                     continue;
                 }
                 try {
                     $error = $this->browser->get($url)->responseIsError();
                 } catch (Exception $e) {
                     continue;
                 }
                 if (!$error) {
                     $this->printDebug('checking: ' . $url);
                     $page = $this->browser->getResponseText();
                     $page = LsHtml::replaceEntities($page);
                     if (!$bio) {
                         if ($bio = $this->findPersonBio($page, $person, $org)) {
                             try {
                                 $this->db->beginTransaction();
                                 $person->summary = $bio;
                                 $person->save();
                                 $person->addReference($url, null, array('summary'), $org->name . ' website');
                                 $this->printDebug("\nBIO FOUND & SAVED: " . $bio . "\n");
                                 $ct = 0;
                                 if (!$this->testMode) {
                                     $this->db->commit();
                                 } else {
                                     $this->db->rollback();
                                 }
                             } catch (Exception $e) {
                                 $this->db->rollback();
                                 throw $e;
                             }
                         } else {
                             $this->printDebug('no bio');
                         }
                     }
                     if (!$image) {
                         if ($image = $this->findPersonImage($page, $person, $org)) {
                             $this->printDebug('IMAGE FOUND: ' . $image['url']);
                             preg_match('/(http\\:\\/\\/[^\\/]+)\\//is', $url, $match);
                             $root_url = $match[1];
                             $image_url = null;
                             if (preg_match('/^http/is', $image['url'])) {
                                 $image_url = $image['url'];
                             } else {
                                 $pos = strrpos($url, '/');
                                 if ($pos > 8) {
                                     $trimmed_url = substr($url, 0, $pos);
                                 } else {
                                     $trimmed_url = $url;
                                 }
                                 if (preg_match('/^\\//is', $image['url'])) {
                                     $image_url = $root_url . $image['url'];
                                 } else {
                                     if (preg_match('/^((\\.\\.\\/)+)(.+)/is', $image['url'], $match)) {
                                         $num_steps = strlen($match[1]) / 3;
                                         for ($i = 0; $i < $num_steps; $i++) {
                                             $trimmed_url = substr($trimmed_url, 0, strrpos($trimmed_url, '/'));
                                         }
                                         $image_url = $trimmed_url . '/' . $match[3];
                                     } else {
                                         $image_url = $trimmed_url . '/' . $image['url'];
                                     }
                                 }
                             }
                             if ($image_url) {
                                 $this->printDebug($image_url);
                                 if ($fileName = ImageTable::createFiles($image_url, $person->name)) {
                                     //insert image record
                                     try {
                                         $this->db->beginTransaction();
                                         $image = new Image();
                                         $image->filename = $fileName;
                                         $image->entity_id = $person->id;
                                         $image->title = $person->name;
                                         $image->caption = 'From ' . $org->name . '\'s website.';
                                         $image->is_featured = true;
                                         $image->is_free = false;
                                         $image->url = $image_url;
                                         $q = LsDoctrineQuery::create()->from('Image i')->where('i.entity_id = ?', $person->id)->addWhere('i.title =?', $person->name)->addWhere('i.caption =?', $image->caption);
                                         if (count($q->execute()) == 0) {
                                             $image->save();
                                             $image->addReference($image_url, null, array('filename'), $org->name . ' website');
                                             if (!$bio) {
                                                 $person->addReference($url, null, null, $org->name . ' website');
                                             }
                                             $this->printDebug("Imported image: " . $image->filename);
                                             $ct = 0;
                                         }
                                         if (!$this->testMode) {
                                             $this->db->commit();
                                         } else {
                                             $this->db->rollback();
                                         }
                                     } catch (Exception $e) {
                                         $this->db->rollback();
                                         throw $e;
                                     }
                                 }
                             }
                         } else {
                             $this->printDebug('no image');
                         }
                     }
                     if ($bio && $image) {
                         break;
                     }
                 } else {
                     $this->printDebug('response is error: ' . $url);
                 }
                 $this->printDebug('-------------');
             }
             if (count($match_sets)) {
                 //var_dump($match_sets);
             }
         } else {
             $this->printDebug("No results found \n");
         }
         if (!$image && !$bio) {
             $ct++;
         }
     }
 }
Ejemplo n.º 19
0
 public function executeUploadImage($request)
 {
     $this->checkEntity($request);
     $params = $request->getParameter('image');
     $this->upload_form = new ImageUploadForm();
     $this->has_image = EntityTable::hasProfileImage($this->entity);
     if ($request->isMethod('post')) {
         $db = Doctrine_Manager::connection();
         $this->upload_form->bind($params, $request->getFiles('image'));
         if ($this->upload_form->isValid()) {
             try {
                 $db->beginTransaction();
                 $files = $request->getFiles('image');
                 //set filename and path based on upload type
                 if (isset($files['file']['size']) && $files['file']['size']) {
                     $path = $request->getFilePath('image');
                     $path = $path['file'];
                     $originalFilename = $request->getFileName('image');
                     $originalFilename = $originalFilename['file'];
                 } else {
                     $path = $params['url'];
                     $pathParts = explode('?', basename($path));
                     $originalFilename = $pathParts[0];
                 }
                 //if image files can't be created, assume remote url was bad
                 if (!($filename = ImageTable::createFiles($path, $originalFilename))) {
                     $validatorSchema = $this->upload_form->getValidatorSchema();
                     $this->upload_form->getErrorSchema()->addError(new sfValidatorError($validatorSchema['url'], 'invalid'));
                     return sfView::SUCCESS;
                 }
                 //create image
                 $image = new Image();
                 $image->entity_id = $this->entity['id'];
                 $image->filename = $filename;
                 $image->title = $params['title'];
                 $image->caption = $params['caption'];
                 $image->url = $params['url'];
                 if (!$this->has_image) {
                     $image->is_featured = true;
                 } elseif (isset($params['is_featured'])) {
                     $db = Doctrine_Manager::connection();
                     $sql = 'UPDATE image SET is_featured = 0 WHERE entity_id = ?';
                     $stmt = $db->execute($sql, array($this->entity['id']));
                     $image->is_featured = true;
                 } else {
                     $image->is_featured = 0;
                 }
                 $image->is_free = isset($params['is_free']) ? true : null;
                 $image->save();
                 //if featured, unfeature any other images
                 if (isset($params['featured']) && ($profileImage = EntityTable::getProfileImageById($entity))) {
                     $profileImage->is_featured = false;
                     $profileImage->save();
                 }
                 $db->commit();
             } catch (Exception $e) {
                 $db->rollback();
                 throw $e;
             }
             $this->clearCache($this->entity);
             $this->redirect($image->url ? EntityTable::getInternalUrl($this->entity, 'images') : 'entity/image?id=' . $image->id);
         }
     }
 }