Exemplo n.º 1
0
         //this will write previous value
     }
 }
 if (!isset($options['mail_password']) || $options['mail_password'] == '') {
     $options['mail_username'] = '';
     $options['mail_smtp_host'] = '';
     $options['mail_smtp_port'] = '';
 }
 if (isset($options['max_recommend']) && !is_numeric($options['max_recommend'])) {
     $options['max_recommend'] = 10;
 }
 //read/write config file
 $fin = fopen('../config.php', 'r');
 $fout = fopen('../config.php.new', 'w');
 while ($line = fgets($fin)) {
     if (string_begins_with($line, '$config[')) {
         $begin_index = strpos($line, "'") + 1;
         $end_index = strpos($line, "'", $begin_index);
         $option_name = substr($line, $begin_index, $end_index - $begin_index);
         if (array_key_exists($option_name, $options) && $options[$option_name] != '') {
             $option_value = $options[$option_name];
             $force_no_quotes = in_array($option_name, $array_options);
             writeOption($fout, $option_name, $option_value, $force_no_quotes);
             unset($options[$option_name]);
         } else {
             fwrite($fout, $line);
         }
     } else {
         if (trim($line) != "?>") {
             //we write this after the extra options below
             fwrite($fout, $line);
    /**
    * Show and process edit link logo form
    *
    * @param void
    * @return null
    */
    function edit_logo() {
      $link = ProjectLinks::findById(get_id());
      if (!($link instanceof ProjectLink)) {
        flash_error(lang('link dnx'));
        $this->redirectToReferer(get_url('links', 'index'));
      } // if

      if (!$link->canEdit(logged_user())) {
        flash_error(lang('no access permissions'));
        $this->redirectToReferer(get_url('links'));
      } // if

      if (!function_exists('imagecreatefromjpeg')) {
        flash_error(lang('no image functions'));
        $this->redirectTo('links');
      } // if

      $this->setTemplate('edit_logo');
      //$this->setLayout('administration');
      
      tpl_assign('link', $link);
      
      $logo = array_var($_FILES, 'new_logo');

      if (is_array($logo)) {
        try {
          $uploaded_file_size = array_var($logo, 'size', 0);
          if ($uploaded_file_size == 0) {
            $x1 = 0 + array_var($_POST, 'x1');
            $y1 = 0 + array_var($_POST, 'y1');
            $x2 = 0 + array_var($_POST, 'x2');
            $y2 = 0 + array_var($_POST, 'y2');
            $url = $link->getUrl();
            if (!string_begins_with($url, 'http://')) $url = 'http://' . $url;
            //die("$x1 $y1 $x2 $y2 $url");
            $img_data = get_content_from_url('wimg.ca', 80, $url);
            if ($img_data) {
              $src_img = imagecreatefromstring($img_data);
              $dst_img = imagecreatetruecolor(50, 50);
              imagecopyresized($dst_img, $src_img, 0, 0, $x1, $y1, 50, 50, abs($x2-$x1), abs($y2-$y1) );

              // Output and free from memory
              //header('Content-Type: image/png');
              $tempname = tempnam(ROOT . '/tmp/', 'links-snapshot' );
              imagepng($dst_img, $tempname);

              $logo["name"]='links-snapshot';
              $logo["tmp_name"]=$tempname;
              $logo["type"]='image/png';
              $logo["size"]='1';

              imagedestroy($dst_img);
              imagedestroy($src_img);
            }
          } else {
            move_uploaded_file($logo["tmp_name"], ROOT . "/tmp/" . $logo["name"]);
            $logo["tmp_name"] = ROOT . "/tmp/" . $logo["name"];
            if (!isset($logo['name']) || !isset($logo['type']) || !isset($logo['size']) || !isset($logo['tmp_name']) || !is_readable($logo['tmp_name'])) {
              throw new InvalidUploadError($logo, lang('error upload file'));
            } // if
          }
          
          $valid_types = array('image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png');
          $max_width   = config_option('max_logo_width', 50);
          $max_height  = config_option('max_logo_height', 50);
          
          if (!in_array($logo['type'], $valid_types) || !($image = getimagesize($logo['tmp_name']))) {
            throw new InvalidUploadError($logo, lang('invalid upload type', 'JPG, GIF, PNG'));
          } // if
          
          $old_file = $link->getLogoPath();
          
          DB::beginWork();
          
          if (!$link->setLogo($logo['tmp_name'], $max_width, $max_height, true)) {
            DB::rollback();
            flash_error(lang('error edit link logo', $e));
            $this->redirectToUrl($link->getEditLogoUrl());
          } // if
          
          ApplicationLogs::createLog($link, active_project(), ApplicationLogs::ACTION_EDIT);
          
          flash_success(lang('success edit logo'));
          DB::commit();
          
          if (is_file($old_file)) {
            @unlink($old_file);
          } // uf
          
        } catch(Exception $e) {
          flash_error(lang('error edit logo', $e));
          DB::rollback();
        } // try
        
        $this->redirectToUrl($link->getEditLogoUrl());
      } // if
    } // edit_logo
Exemplo n.º 3
0
function processFileSubmission($array)
{
    $config = $GLOBALS['config'];
    $answers = array();
    foreach ($array as $key => $value) {
        if (string_begins_with($key, "a_")) {
            $parts = explode("_", substr($key, 2));
            if (count($parts) == 3) {
                $var_id = $parts[0];
                $answer_id = $parts[1];
                $repeat_id = $parts[2];
                $answers[$var_id] = array($answer_id, $key);
            }
        }
    }
    return $answers;
}